想通过frame的button跳转到javafx的listview

想通过frame的button跳转到javafx的listview,发现第一次关闭javafx窗口后再次打开就会报错,因为它提示Application launch must not be called more than once,问题是我窗口已经关闭了,不能被调用两次怎么解决呢?

frame上的button监听代码如下:
button.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new Thread(new Runnable() {
//

@Override
public void run() {
// TODO Auto-generated method stub
ListViewSample listViewSample=new ListViewSample();
listViewSample.main(null);
//listViewSample.start(null);
}
}).start();

// listViewSample.main();
}
});

javafx代码如下
public class ListViewSample extends Application {

// public static final ObservableList data

// = FXCollections.observableArrayList();

public ObservableList<String> strList=FXCollections.observableArrayList("红色","黄色","绿色");

public static void main(String[] args) {  
    launch(args);
}  

@Override  
public void start(Stage primaryStage) {  

    //Platform.setImplicitExit(true);
    primaryStage.setTitle("List View Sample");   

    ListView<String> listView2=new ListView<>();
    listView2.setItems(strList);
    listView2.setPrefSize(400, 200);
    StackPane root = new StackPane();  
    root.getChildren().add(listView2);  
    primaryStage.setScene(new Scene(root, 400, 200));  
    primaryStage.show(); 
    primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
        @Override
        public void handle(WindowEvent event) {
            System.out.print("监听到窗口关闭");


        }
    });
    listView2.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Object>() {

@Override
public void changed(ObservableValue<? extends Object> observable, Object oldValue, Object newValue) {
// TODO Auto-generated method stub
EsitFrame esitFrame=new EsitFrame();
esitFrame.setVisible(true);
System.out.println(newValue);
// frame.add(label);

}
});
}

主要是想实现点击button传输指令到单片机,单片机返回的数据利用listview显示返回的数据,然后点击每个item再触发其他事件

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问