java - 保存输入数据 JavaFX
问题描述
我是编程新手,正在上 OOP 课程。我正在尝试提出一个 JavaFX 应用程序,它可以保存情绪输入以便能够收集数据。截至目前,数据必须在控制台命令窗口中,但在添加新输入时会被替换。任何方向将不胜感激。
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class comboBoxPTSD extends Application {
Stage window;
Scene scene;
Button button;
ComboBox<String> comboBox;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
window = primaryStage;
window.setTitle("PTSD Tracker App");
button = new Button("Submit");
comboBox = new ComboBox<>();
comboBox.getItems().addAll(
"Happy", "Content", "Good", "Sad", "Angry",
"Hopeless", "Suicidal");
//sets combo boxes text name.
comboBox.setPromptText("How are you doing today?");
comboBox.setEditable(true);
/*
* can set the comboBox to input user input with
*"comboBox.setEditable(true);"
*will override box name.
*want to save input and output...
*
*use variable string.
*/
button.setOnAction(e -> printMood());
//ComboBoxes also generate actions if you need to get value instantly
comboBox.setOnAction( e -> System.out.println("User selected " + comboBox.getValue()) );
VBox layout = new VBox(10);
layout.setPadding(new Insets(20, 20, 20, 20));
layout.getChildren().addAll(comboBox, button);
scene = new Scene(layout, 300, 250);
window.setScene(scene);
window.show();
}
private void printMood(){
System.out.println(comboBox.getValue());
}
}
解决方案
推荐阅读
- python-3.x - python中的doopl参数设置
- sql - 在 SQL 中,有没有办法拆分 SQL 中存储为列表的列?
- ruby-on-rails - 在 ruby on rails 中自定义 JSON 响应
- sql - 从 Presto SQL 中的字符串获取日期
- regex - 在 grep/pgrep 过滤器中不使用 -v 不是“x”或“y”?
- ansible - 如何使用 Ansible 从另一个列表中删除子列表
- php - 邮递员中的PHP服务器响应低于1000MS,但不是通过设备应用程序
- kubernetes - 如何指定 ServiceAccount 由 kubernetes python sdk 中的 config.load_incluster_config() 获取
- python - 我应该使用夹具来执行设置功能吗?
- python - StackingClassifier 导致“ValueError:输入形状错误”错误