http://expert.csdn.net/Expert/topic/2351/2351047.xml?temp=.849972

解决方案 »

  1.   

    在这个按钮的事件监听器中将另一个窗体setSize,然后再show。当然另一个窗体的实例必须事先创建。
      

  2.   

    jb1 = new JButton("OK");
    jb1.setActionCommand("ok");
    jb1.addActionListener(this);
    public void actionPerformed(ActionEvent ae) { String str=ae.getActionCommand(); if (str.equals("ok"))

      studentchangeinfo sci = new  studentchangeinfo();
      sci.init();
      sci.setVisible(true); }
      

  3.   

    *.init() 那句要看你自己的程序,如果直接用的constructot,就不用写了
      

  4.   

    我用的是JB,请问可不可以向VB和delphi那样,先设计好一个窗体然后再调用它
      

  5.   

    当然可以,先设计好,设成setVisible(false);需要时再设成setVisible(true);
      

  6.   

    说详细一点吧,比如我的另一个窗体是导入的的图片,设为MAP.java,应该在前一个按扭中怎么设置点击后出现MAP?
      

  7.   

    to realzealy(国米无敌),我在jb中建立了2个frame,但在frame1中无法调用frame2呀
      

  8.   

    我做了个例子供参考:
    import java.awt.event.*;
    import javax.swing.*;class aa extends JFrame implements ActionListener
    {
     JButton buttonFrame2;
     JFrame frame2;
     JPanel pane;
     
     aa()
     {
      super("Frame test");
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      
      buttonFrame2=new JButton("打开Frame2");
      buttonFrame2.addActionListener(this);
      pane=new JPanel();
      pane.add(buttonFrame2);
      getContentPane().add(pane);
      setSize(300,300);
      show();
      
      frame2=new JFrame("Frame2");
      frame2.setSize(200,200);
      frame2.setVisible(false);
     }
     
     public static void main(String[] arguments)
     {
      aa a=new aa();
     }  
     
     public void actionPerformed(ActionEvent evt)
     {
      Object obj=evt.getSource();
      if(obj instanceof JButton)
        {
         JButton source=(JButton)obj;
         
         //注意下面的代码实现显示第2个窗口
         if(source==buttonFrame2)
           {
            frame2.setVisible(true); 
           }  
        }
      }
    }
      

  9.   

    我的类名aa起的太差了,原因是在IDE里给JAVA文件随便起了名字aa,结果弄的类名也改成了aa,也没有大写第一个字母,惭愧
      

  10.   

    建议大家明白这个后去我的帖子上看看,研究更深入的,谢谢!http://expert.csdn.net/Expert/topic/2366/2366198.xml?temp=.225857