java 窗口跳转

来源:百度知道 编辑:UC知道 时间:2024/09/18 05:54:50
就是一个窗口中有一个按钮,点击这个按钮打开另外一个,原来那个隐藏!
越简单越好,......请附完整程序!

//////我已经把程序写的够简单了,一看就明白//
import java.awt.*;
import java.awt.event.*;
public class MyFrame extends JFrame implements ActionListener {
private JPanel pan;
private JButton but;

MyFrame(){
this.setBounds(100, 100, 200, 200);
pan = new JPanel();
but = new JButton("点我出来新窗口");
but.addActionListener(this);
pan.add(but);
this.add(pan);
this.setAlwaysOnTop(true);
this.setVisible(true);
}
public static void main(String args[]){
new MyFrame();
}

public void actionPerformed(ActionEvent e) {
if(e.getSource()==but){
this.setVisible(false);
new Another();
}

}
class Another extends JFrame{
Another(){
this.setTitle("新窗口");
this.setBounds(300, 300, 200, 200);
this.setAlwaysOnTop(true);
this.setVisible(true);
}
}

}