我有一个名为“添加爆米花”,“添加玉米片”和“添加热狗”的按钮,以及一个名为“ snacklistview”的列表视图。 所以我想要的是当我单击“添加爆米花”按钮时,我希望详细信息显示在列表视图中。 这就是我想要列表视图的样子。
爆米花1.50
我希望每次单击按钮时都进行更新。
public class SnacksController {
public Snacks nachos;
public Snacks hotdog;
public Snacks popcorn;
public Button popcornbutton;
public Button nanchosbutton;
public Button hotdogbutton;
public TextArea snacktextarea;
public Label snacktotal;
public Button snacktotalbutton;
public ListView snacklistview;
@FXML
public void printpopcorn(ActionEvent actionEvent) {
popcornbutton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
snack'\n'+"popcorn");
}
});
popcorn = new Snacks(" Popcorn", 0,1.50);
nachos = new Snacks(" Nachos", 0,1.75);
hotdog = new Snacks(" Hotdogs", 0, 2);
}
@FXML
public void printnachos(ActionEvent actionEvent) {
nanchosbutton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
snacktextarea.appendText('\n'+"nachos");
}
});
}
@FXML
public void printhotdog(ActionEvent actionEvent) {
hotdogbutton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
snacktextarea.appendText('\n'+"Hotdog");
}
});