forked from michael-taylor/Sample-JavaFxController
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestDialog.java
More file actions
77 lines (63 loc) · 1.81 KB
/
TestDialog.java
File metadata and controls
77 lines (63 loc) · 1.81 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
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
package sample;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
public class TestDialog extends Stage implements Initializable
{
@FXML
private TextField addressTextBox;
@FXML
private Button okButton;
@FXML
private TextField nameTextBox;
private String defaultName;
private String defaultAddress;
public TestDialog(String defaultName, String defaultAddress, Parent parent)
{
setTitle("This is a test dialog");
this.defaultName = defaultName;
this.defaultAddress = defaultAddress;
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("TestDialog.fxml"));
fxmlLoader.setController(this);
// Nice to have this in a load() method instead of constructor, but this seems to be de-facto standard.
try
{
setScene(new Scene((Parent) fxmlLoader.load()));
}
catch (IOException e)
{
e.printStackTrace();
}
}
@FXML
void onOkButtonAction(ActionEvent event)
{
close();
}
public String getName()
{
return nameTextBox.getText();
}
public String getAddress()
{
return addressTextBox.getText();
}
/*
* Called when FXML file is load()ed (via FXMLLoader.load()). It will execute before the form is shown.
*/
@Override
public void initialize(URL url, ResourceBundle resourceBundle)
{
nameTextBox.setText(defaultName);
addressTextBox.setText(defaultAddress);
}
}