0

我正在学习使用 Java 教程(使用 NetBeans IDE 学习 Swing课程)做一些 GUI,并且我已经完成了他们教授的项目,到目前为止一切正常。

但是,问题来了,我怎样才能制作一个程序,首先在 aJFrame或 a中JPanel显示一条消息Hello User和一个按钮Enter摄氏到华氏的转换器,就像我给出的页面中的示例一样?

如果您需要这些信息,我使用的是 Netbeans IDE 8.1

4

1 回答 1

1

In any of the event handlers for the first JFrame just create an object of the class for second JFrame and setVisible(true) on the new JFrame and then this.setVisible(false).

eg. in class JFrameOne there is a button which when clicked calls:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    new JFrameTwo().setVisible(true);
    this.setVisible(false);
} 

The link Andrew Thompson provided includes a lot of discussion from people with strong opinions about whether this is good practice, but I suggest you try it, consider the alternatives and make up your own mind. At the very least it is easy to do.

于 2015-12-04T14:39:41.127 回答