[英]How to open new JFrame by clicking on button in other JFrame?
I write project in Java in NetBeans. 我在NetBeans中用Java编写项目。 I created a new project and didn't check to create main class, because I create all with drag and drop, make some buttons and events on them.
我创建了一个新项目,没有检查要创建主类,因为我通过拖放操作创建了所有类,并在它们上创建了一些按钮和事件。 Then, I created two
JFrame
classes: NewJFrame
and NewJFrame1
, in NewJFrame
I a have a button in both frames. 然后,我创建了两个
JFrame
类: NewJFrame
和NewJFrame1
,在NewJFrame
中,两个框架中都有一个按钮。
So, can you tell me how can I make event to open first frame by clicking on button in second frame, and to open second frame by clicking on button in first frame? 那么,您能告诉我如何通过单击第二帧中的按钮来打开第一帧,以及通过单击第一帧中的按钮来打开第二帧吗?
//Make constructor class for both JFrame then
//write this code into your JFrame where your button is accesing another JFrame
//Note:- jb=button var name,
// jf=JFrame vatr name,
// addnew()=JFrame Class to be open.
jb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
new addnew();
jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.