标签:win alt dialog 桌面 javafx roo release action tac
//起因:因为即便是使用了JavaFX Scene Builder来直接图形化排版,但是仍然对应javaAPI,了解整体结构还是很有必要的,这是有清晰逻辑的基础。
environment:{
Spring Tool Suite
Version: 3.8.4.RELEASE
Build Id: 201703310825
Platform: Eclipse Neon.3 (4.6.3)
}
1 package application; 2 3 import javax.swing.JOptionPane; 4 import javafx.application.Application; 5 //import javafx.event.ActionEvent; 6 import javafx.stage.Stage; 7 import javafx.scene.Scene; 8 //import javafx.scene.control.Alert; 9 //import javafx.scene.control.Alert.AlertType; 10 import javafx.scene.control.Button; 11 //import javafx.scene.control.Dialog; 12 //import javafx.scene.layout.BorderPane; 13 import javafx.scene.layout.FlowPane; 14 public class Main extends Application { 15 @Override 16 public void start(Stage primaryStage) { 17 try { 18 FlowPane root = new FlowPane(); 19 //-----------------test-----------------add----------( 20 Button button = new Button("hello JavaFX"); 21 root.getChildren().add(button); 22 button.setOnAction((event)->{//lambda表达式 23 //不会用FX的弹出对话框 24 JOptionPane.showMessageDialog(null, "Hello JavaFX"); 25 }); 26 //-----------------test-----------------add----------) 27 Scene scene = new Scene(root,400,400); 28 scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm()); 29 primaryStage.setScene(scene); 30 primaryStage.show(); 31 } catch(Exception e) { 32 e.printStackTrace(); 33 } 34 } 35 36 public static void main(String[] args) { 37 launch(args); 38 39 } 40 }
2.way2:way1不要直接Finish,next到最后,Declarative UI->language:FXML
1 package application; 2 3 import javafx.application.Application; 4 import javafx.stage.Stage; 5 import javafx.scene.Scene; 6 import javafx.scene.layout.FlowPane; 7 import javafx.fxml.FXMLLoader; 8 9 10 public class Main extends Application { 11 @Override 12 public void start(Stage primaryStage) { 13 try { 14 FlowPane root = (FlowPane)FXMLLoader.load(getClass().getResource("Sample.fxml")); 15 Scene scene = new Scene(root,400,400); 16 scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm()); 17 primaryStage.setScene(scene); 18 primaryStage.show(); 19 } catch(Exception e) { 20 e.printStackTrace(); 21 } 22 } 23 24 public static void main(String[] args) { 25 launch(args); 26 } 27 }
标签:win alt dialog 桌面 javafx roo release action tac
原文地址:http://www.cnblogs.com/zeigongzi/p/7071440.html