public class test extends JFrame {
//private static final long serialVersionUID = -2865136880741559697L;
public test(){
JFrame jf=new JFrame("主窗体");
JMenuBar jmb=new JMenuBar();
JMenu jm=new JMenu("文件");
final JMenuItem jmi=new JMenuItem("打开");
jm.add(jmi);
jmb.add(jm);
jf.getContentPane().add(jmb);
jf.setSize(500,500);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
jmi.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Object oo=e.getSource();
if(oo.equals(jmi))
{new test2();
}
}});
};
public static void main(String[] args) {
new test();
}
}
----------
import javax.swing.JFrame;
public class test2 extends JFrame{
public test2(){
JFrame jf=new JFrame("2窗体");
jf.setSize(300,300);
jf.setVisible(true);
}
public static void main(String[] args) {
new test2();
}