snowbird2005
米兰大脑
发贴: 72
积分: 10
|
于 2005-06-13 00:48
以下代码供参考:
import java.awt.Button; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;
import javax.swing.JFrame;
public class FirstFrame extends JFrame implements ActionListener { private Button firstButton,secondButton; JFrame secondFrame = new JFrame("Second Frame"); public FirstFrame() { super("First Frame"); firstButton=new Button("show second frame"); setLayout(new FlowLayout()); firstButton.addActionListener(this); add(firstButton); setVisible(true); setSize(300,300); setDefaultCloseOperation(EXIT_ON_CLOSE); secondButton=new Button("show first frame"); secondFrame.setLayout(new FlowLayout()); secondFrame.setSize(400,300); secondFrame.add(secondButton); secondFrame.setDefaultCloseOperation(EXIT_ON_CLOSE); secondButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(true); secondFrame.setVisible(false); } });
secondFrame.setVisible(false); } public void actionPerformed(ActionEvent e) { setVisible(false); secondFrame.setVisible(true); } public static void main(String[] args) { new FirstFrame(); }
}
|