java 多窗口_java中怎么做多窗体界面?

这是两种窗体,你写在JButton的事件里就行了

java code:

/*

* NewJFrame.java

*

* Created on 2011-3-1, 16:22:14

*/

/**

*

* @author 丁乔武

* 398142885@QQ.com

*/

public class NewJFrame extends javax.swing.JFrame {

public NewJFrame() {

initComponents();

}

private void initComponents() {

javax.swing.JButton btnShow = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

setTitle("测试");

setResizable(false);

btnShow.setText("显示窗体");

btnShow.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btnShowActionPerformed(evt);

}

});

getContentPane().add(btnShow, java.awt.BorderLayout.PAGE_END);

pack();

java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();

java.awt.Dimension dialogSize = getSize();

setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2);

}

private void btnShowActionPerformed(java.awt.event.ActionEvent evt) {

new NewJFrame().setVisible(true);

}

/**

* @param args the command line arguments

*/

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new NewJFrame().setVisible(true);

}

});

}

}


版权声明:本文为weixin_42412850原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。