编程语言
首页 > 编程语言> > 一个简单的JavaFXHelloWorld窗口程序

一个简单的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);
		// -----------------------------------------------------------
	}
}

 

标签:primaryStage,JavaFXHelloWorld,void,程序,hello,pane,new,窗口,public
来源: https://blog.csdn.net/yyxgs/article/details/110368280