-
Notifications
You must be signed in to change notification settings - Fork 0
/
first.java
71 lines (61 loc) · 2.03 KB
/
first.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
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
/**
* Write a description of JavaFX class first here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class first extends Application
{
// We keep track of the count, and label displaying the count:
private int count = 0;
private Label myLabel = new Label("0");
/**
* The start method is the main entry point for every JavaFX application.
* It is called after the init() method has returned and after
* the system is ready for the application to begin running.
*
* @param stage the primary stage for this application.
*/
@Override
public void start(Stage stage)
{
// Create a Button or any control item
Button myButton = new Button("Count");
// Create a new grid pane
GridPane pane = new GridPane();
pane.setPadding(new Insets(10, 10, 10, 10));
pane.setMinSize(300, 300);
pane.setVgap(10);
pane.setHgap(10);
//set an action on the button using method reference
myButton.setOnAction(this::buttonClick);
// Add the button and label into the pane
pane.add(myLabel, 1, 0);
pane.add(myButton, 0, 0);
// JavaFX must have a Scene (window content) inside a Stage (window)
Scene scene = new Scene(pane, 300,100);
stage.setTitle("JavaFX Example");
stage.setScene(scene);
// Show the Stage (window)
stage.show();
}
/**
* This will be executed when the button is clicked
* It increments the count by 1
*/
private void buttonClick(ActionEvent event)
{
// Counts number of button clicks and shows the result on a label
count = count + 1;
myLabel.setText(Integer.toString(count));
}
}