从另一个类打开一个jFrame

时间:2015-12-26 16:52:07

标签: java swing jframe netbeans-8

我试图通过点击课程 A 中的按钮来打开课程 B 中的JFrame。我在项目中使用JFrameForm。我怎么做到这一点?

我尝试使用此代码,它成功打开了Class B (JDBC_Trial)中的JFrame,但没有关闭类 A
     

 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new JDBC_Trial().setVisible(true);
} }); // TODO add your handling code here: }

2 个答案:

答案 0 :(得分:0)

使用调度事件可以选择帧的内容。在这里,我关闭了它:

frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
JDBC_Trial p = new JDBC_Trial();
p.setVisible(true);

答案 1 :(得分:-1)

不推荐,但有可能:

Download download = new Download();
download.setDefaultCloseOperation(download.HIDE_ON_CLOSE);
download.setVisible(true);

只需将其添加到您要调用的事件上即可。

相关问题