当我在PieChart
中按PrimaryStage
时,我想在JButton
中重新开启JFrame
但在PrimaryStage
的所有场景都关闭时无效。
每当我按下按钮时,你能帮助我在初级阶段重新启动饼图吗?
...
btnNewButton_1 = new JButton("check_1");
btnNewButton_1.setBounds(14, 146, 180, 44);
btnNewButton_1.addActionListener(this);
getContentPane().add(btnNewButton_1);
button_1 = new JButton("check_2");
button_1.setBounds(14, 202, 180, 44);
button_1.addActionListener(this);
getContentPane().add(button_1);
...
@Override
public void actionPerformed(ActionEvent e) {
...
else if (e.getSource() == btnNewButton_1) {
new JFXPanel();
Platform.runLater(new Runnable() {
@Override
public void run() {
try {
new AverageGender().start(new Stage());
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
...
private class AverageGender extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("check_1");
Group root = new Group();
ObservableList<PieChart.Data> pieChartData = FXCollections
.observableArrayList(new PieChart.Data("Male", 20), new PieChart.Data("Female", 60));
final PieChart pieChart = new PieChart(pieChartData);
pieChart.setTitle("check_1");
root.getChildren().add(pieChart);
primaryStage.setScene(new Scene(root, 500, 400));
primaryStage.setResizable(true);
primaryStage.show();
}
}