javafx小程序的知识点

本文深入探讨了JavaFX技术,重点讲解如何利用它来创建小型应用程序。内容包括JavaFX的基础概念,UI组件的使用,事件处理,以及应用程序打包和部署的步骤。通过实例,读者将了解到JavaFX为桌面应用提供的强大功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

					1.RootController

package application;
import application.Context;

public class RootController {
	public RootController(){
        //初始化时保存当前Controller实例
        Context.controllers.put(this.getClass().getSimpleName(), this);
    }
}



					2.ContextController
package Controller;
import java.util.HashMap;
import java.util.Map;

public class ContextController {
	//Controller容器
    	public static Map<String, Object> controllers = new HashMap<String, Object>();
	
	public static Map<String, Object> getControllers() {
		return controllers;
	}
}

	
举例应用

public class UiController extends RootController implements Initializable
System.out.println(ContextControll.getControllers());
//从容器中获取FunctionController实例
UiController controller = 
	(UiController) ContextController.controllers.get(UiController.class.getSimpleName());
controller.serverForLeastRest((ArrayList<ProcessControllBlock>)readyQueue, freePCBList,iBlock);




							3.线程启动
	
Thread t = new Thread(new Runnable(){
public void run(){
  	Context_Strategy context_Strategy = new Context_Strategy(new Least_Rest_Strategy(),initFree_ReadyQueue.readyQueue,initFree_ReadyQueue.freePCBList);
        		context_Strategy.selected_method();
            }});
t.start();



						4.子线程控制速度
Thread thread = Thread.currentThread();
try {
	thread.sleep(1000);
} catch (InterruptedException e) {
	e.printStackTrace();
}




			5.即时更新UI界面(与子线程速度一致,都为1000ms,但是实时更新)
EventHandler<ActionEvent> eventHandler = e->{
	    //操作
	};
Timeline animation = new Timeline(new KeyFrame(Duration.millis(1000), eventHandler));
animation.setCycleCount(Timeline.INDEFINITE  // 1); //可以只显示一次
animation.play();




							6.深度复制
public  InitFree_ReadyQueue  independent_copy(InitFree_ReadyQueue source) {
	ArrayList<ProcessControllBlock> target_ready =  new ArrayList<ProcessControllBlock>(source.readyQueue.size());
	ArrayList<ProcessControllBlock> target_free = new ArrayList<ProcessControllBlock>(source.freePCBList.size());
	
	for(int i=0,max = source.readyQueue.size();i<max;i++) {
		target_ready.add(new ProcessControllBlock(source.readyQueue.get(i).getPid(),source.readyQueue.get(i).getState(),source.readyQueue.get(i).getServertime(),source.readyQueue.get(i).getPriority(),source.readyQueue.get(i).getStart_time()));
	}
		
	for(int i=0,max = source.freePCBList.size();i<max;i++) {
		target_free.add(new ProcessControllBlock(source.freePCBList.get(i).getPid(),source.freePCBList.get(i).getState(),source.freePCBList.get(i).getServertime(),source.freePCBList.get(i).getPriority(),source.freePCBList.get(i).getStart_time()));
	}
		
	return new InitFree_ReadyQueue(target_free,target_ready);
}


public class InitFree_ReadyQueue implements Cloneable{
	public ArrayList<ProcessControllBlock> freePCBList;
	public List<ProcessControllBlock> readyQueue;
	
	public InitFree_ReadyQueue(ArrayList<ProcessControllBlock> freePCBList, List<ProcessControllBlock> readyQueue) {
		super();
		this.freePCBList = freePCBList;
		this.readyQueue = readyQueue;
	}
	
}

							7.listview 显示
ObservableList<String> strReadyList = FXCollections.observableArrayList();
ObservableList<String> strFreeList = FXCollections.observableArrayList();


Iterator<ProcessControllBlock> iterator  = readyQueue.iterator();
ProcessControllBlock temp = null;

while (iterator.hasNext() && readyQueue.size() != 0) {
	temp  = iterator.next();
	strReadyList.add(temp.toString());
}
			
short_ready.setItems(strReadyList);  //重点!!



						8.多线程重要问题
		如果偶尔出现没代码端出错的异常,就说明一些函数要public synchronized  修饰  ---同步

						9.多线程仍有疑惑..还在完成..
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值