-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHelloController.java
More file actions
52 lines (38 loc) · 1.22 KB
/
HelloController.java
File metadata and controls
52 lines (38 loc) · 1.22 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
package com.example;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
/**
* Controller layer: mediates between the view (FXML) and the model.
*/
public class HelloController {
private final HelloModel model = new HelloModel(new NtfyConnectionImpl());
public ListView<NtfyMessageDto> messageView;
@FXML
private Label messageLabel;
@FXML
private TextField inputField;
@FXML
private TextField topicField;
@FXML
private void initialize() {
if (messageLabel != null) {
messageLabel.setText(model.getGreeting());
}
inputField.textProperty().bindBidirectional(model.messageToSendProperty());
topicField.textProperty().bindBidirectional(model.topicProperty());
messageView.setItems(model.getMessages());
model.connectToTopic();
}
public void sendMessage(ActionEvent actionEvent) {
if (!inputField.getText().trim().isEmpty()) {
model.sendMessage();
inputField.clear();
}
}
public void connectToTopic(ActionEvent actionEvent) {
model.connectToTopic();
}
}