Repository navigation
Expand file tree
/
Copy pathmain3.java
More file actions
51 lines (42 loc) · 1.72 KB
/
Copy pathmain3.java
File metadata and controls
51 lines (42 loc) · 1.72 KB
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
import javafx.application.Application;
import javafx.scene.control.Button;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
/**
* Created by Dynee on 6/2/16.
*/
public class main3 extends Application {
Button button;
// the launch method is the first method called in a javafx app,
// it sets up configuration information
// start is the second method called which sets up the look of the app.
public static void main1(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
// sets title of the Stage
// stage is your window, scene is everything inside the window
primaryStage.setTitle("JavaFX Tutorial");
// gives text to button
button = new Button();
button.setText("Click Me!");
// this code says when you click the button look for the code to handle it, in this class
// you could create a separate class to handle events if you want.
// this can also be done using a lambda expression which is way simpler.
button.setOnAction(e -> System.out.println("HELLO WORLD"));
// alligns button in the center
// layout sets up how you want everything to look
StackPane layout = new StackPane();
layout.getChildren().add(button);
// need to pass the scene object to the setScene method of primaryStage
// this creates the scene inside your stage
// the show method displays the scene to the user.
Scene scene = new Scene(layout, 300, 300);
primaryStage.setScene(scene);
primaryStage.show();
}
}