怎么把一个java编写的简单计算器替换到主窗口所连的Another的位置主窗口publicclassMyFrameextendsJFrameimplementsActionListener{privateJPanelpan;privateJButtonbut;MyFrame(){th...
怎么把一个java编写的简单计算器替换到主窗口所连的Another的位置
主窗口
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);
}
}
}
展开