我想要单击一个按扭然后弹出另一个窗体如何弄??
请给个例题,以供参考,谢谢
QQ275632924
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;public class ShowFrame extends JFrame implements ActionListener {
private JButton b;
private JPanel p;
public ShowFrame(String title) {
super(title);
p = new JPanel();
b = new JButton(\"Show\");
b.addActionListener(this);
p.add(b);
getContentPane().add(p);
}
public void actionPerformed(ActionEvent e) {
new TempFrame(this);
}
public static void main(String[] args) {
ShowFrame f = new ShowFrame(\"ShowFrame\");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(200,400);
f.setVisible(true);
}
}class TempFrame extends JDialog {
public TempFrame(ShowFrame f) {
super(f,\"Temp\",true);
setSize(100,100);
setVisible(true);
}
}
现在show已经过时了,不推荐 使用了
取而代之的是setVisible(true)