-
Notifications
You must be signed in to change notification settings - Fork 1
/
MyMain.java
109 lines (89 loc) · 3.34 KB
/
MyMain.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package com.shubhankar.JavaFxapp;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import java.util.Optional;
public class MyMain extends Application {
public static void main(String[] args){
System.out.println("main");
launch(args);
}
@Override
public void init() throws Exception {
System.out.println("init");
super.init();
}
@Override
public void start(Stage primaryStage) throws Exception {
System.out.println("Start");
FXMLLoader loader = new
FXMLLoader(getClass().getResource("app_layout.fxml"));
VBox rootNode = loader.load();
MenuBar menuBar = createMenu();
rootNode.getChildren().add(0,menuBar);
Scene scene = new Scene(rootNode);
primaryStage.setScene(scene);
primaryStage.setTitle("Temperature Converter Tool");
primaryStage.show();
}
private MenuBar createMenu(){
//file menu
Menu fileMenu = new Menu("File");
MenuItem newMenuItem = new MenuItem("New");
newMenuItem.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
System.out.println("new menu item clicked");
}
});
SeparatorMenuItem separatorMenuItem = new SeparatorMenuItem();
MenuItem quitMenuItem = new MenuItem("Quit");
quitMenuItem.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
Platform.exit();
System.exit(0);
}
});
fileMenu.getItems().addAll(newMenuItem,separatorMenuItem,quitMenuItem);
//help menu
Menu helpMenu = new Menu("Help");
MenuItem aboutApp = new MenuItem("About");
aboutApp.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
aboutApp();
}
});
helpMenu.getItems().addAll(aboutApp);
//menu Bar
MenuBar menuBar = new MenuBar();
menuBar.getMenus().addAll(fileMenu,helpMenu);
return menuBar;
}
private void aboutApp() {
Alert alertDialog = new Alert(Alert.AlertType.INFORMATION);
alertDialog.setTitle("My first desktop app");
alertDialog.setHeaderText("Learning java");
alertDialog.setContentText("i am just a beginner");
ButtonType yesBtn = new ButtonType("Yes");
ButtonType noBtn = new ButtonType("No");
alertDialog.getButtonTypes().setAll(yesBtn,noBtn);
Optional<ButtonType> clickedBtn = alertDialog.showAndWait();
if(clickedBtn.isPresent() && clickedBtn.get() == yesBtn){
System.out.println("yes button clicked");
}else {System.out.println("no button clicked");}
}
@Override
public void stop() throws Exception {
System.out.println("Stop");
super.stop();
}
}