一个简单的JavaFXHelloWorld窗口程序

public class Main extends Application
{		
	public static void main(String[] args) throws Exception
	{	
		Application.launch(args);
	}
	
	@Override
	public void start(final Stage primaryStage) throws Exception 
	{
		Pane pane = new Pane();
		
		Value value = new Value();
		
		value.pane = pane;
		
		TextPane hello = new TextPane(value.pane, "HelloWorld");
		hello.setFont("Courier New", 30);
		hello.setFill(Color.RED);
		hello.setLayoutXY(100, 100);
		hello.addToPane();
		
		// 背景颜色
		pane.setBackground(new Background(new BackgroundFill(Color.rgb(200, 200, 200), null, null)));
		
		// ---------------------------窗口----------------------------
		Scene scene = new Scene(pane, 450, 550);
		primaryStage.getIcons().add(new Image("/Script/icon.png"));
		primaryStage.setTitle("");
		primaryStage.setScene(scene);
		primaryStage.show();
		
		// 右上角点击关闭时, 结束子线程
		primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() 
		{
		    public void handle(WindowEvent event) 
		    {
		        System.exit(0);
		    }
		});
		
		// 两次ESC退出程序
		primaryStage.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() 
		{
			int count = 0;
			
			@Override
			public void handle(KeyEvent event)
			{
				if (event.getCode() == KeyCode.ESCAPE)
				{
					++count;
					if (count == 2)
					{
						System.exit(0);
					}
				}
				else
				{
					count = 0;
				}
			}
		});
		
		primaryStage.setResizable(false);
		// -----------------------------------------------------------
	}
}

一个简单的JavaFXHelloWorld窗口程序

 

上一篇:Tmux配置文件大全


下一篇:Linux——tmux和vim常用命令总结(必会)