/** 各位高手,帮我看看要怎么改啊~ 程序意图是在SFTFrame上点击按钮,然后FFrame就出现了并显示一句话(label)*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ShowFrameTest
{ public static void main(String[] arg)
{ JFrame f = new SFTFrame();
f.show();
}
}
class SFTFrame extends JFrame
implements ActionListener
{ public SFTFrame()
{ setSize(500, 350);
Container contentPane = getContentPane();
p = new JPanel();
contentPane.add(p);
button = new JButton("PRESS ME!");
p.add(button);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent evt)
{ ff = new FFrame();
ff.show();
button.addActionListener(ff);
}
private JButton button;
public JFrame ff;
private JPanel p;
}
class FFrame extends JFrame
implements ActionListener
{ public FFrame()
{ setSize(100, 70);
setLocation(400, 400);
Container contentPane = getContentPane();
pp = new JPanel();
contentPane.add(pp);
label = new JLabel("YOU DID IT!~");
}
public void actionPerformed(ActionEvent evt)
{ pp.add(label);}
private JPanel pp;
private JLabel label;
}