你这种方法不对,若想在frame2中调用frame1得先将frame1传入frame2中

解决方案 »

  1.   

    JFrame frame2 = new jFrame("第二个窗体");
    frame2是一个新的Frame而不是原来的那个
      

  2.   

    to jndszl(jj)我试了也不行。
      

  3.   

    但frame2 上的东西比如按钮等都不见了,为什么?你的代码没有问题
    为什么frame2上按钮等不见了?因为frame2上面压根就没有按钮或其他的东西,是空界面
    frame2是什么类型的?是JFrame类型的,java系统自带的类
    JFrame frame2 = new jFrame("第二个窗体");
      

  4.   

    to ilka():谢谢,望你详细说明?
      

  5.   

    to alphazhao(绿色咖啡) :谢谢!但实际上我在frame2上放了按钮等
      

  6.   

    TO 大家我知道frame2是一新的,在我创建它时我又在它(frame2)上面放了按钮等控件
      

  7.   

    刚才没有注意你是new jFrame()
    贴出jFrame calss的源代码
    我怀疑你的布局有问题,或许按钮在(400,300)以外……
      

  8.   


    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;class MulticastPanel extends JPanel 
       implements ActionListener
    {  public MulticastPanel()
       {  JButton newButton = new JButton("New");
          add(newButton);
          newButton.addActionListener(this);       closeAllButton = new JButton("Close all");
          add(closeAllButton);
       }   public void actionPerformed(ActionEvent evt)
       {  
          SimpleFrame f = new SimpleFrame();
          counter++;
          f.setTitle("Window " + counter);
          f.setSize(200, 150);
          f.getContentPane().add(new JButton("Button " + counter),BorderLayout.NORTH);
          f.setLocation(30 * counter, 30 * counter);
          f.show();
          closeAllButton.addActionListener(f);
       }   private int counter = 0;   
       private JButton closeAllButton;
    }   class MulticastFrame extends JFrame
    {  public MulticastFrame()
       {  setTitle("MulticastTest");
          setSize(300, 200);
          addWindowListener(new WindowAdapter()
             {  public void windowClosing(WindowEvent e)
                {  System.exit(0);
                }
             } );      Container contentPane = getContentPane();
          contentPane.add(new MulticastPanel());   
       }
    }public class MulticastTest
    {  public static void main(String[] args)
       {  JFrame frame = new MulticastFrame();
          frame.show();  
       }
    }class SimpleFrame extends JFrame 
       implements ActionListener
    {  public void actionPerformed(ActionEvent evt)
       {  
          dispose();
       }
    }
      

  9.   

    其实我的问题是就象在DELPHI中那样在一窗体中调用另一窗体