怎样实现弹出一个已经做好的界面? Frame2 frame;frame.pack();frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);frame.setVisible(true); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Frame2 frame = new Frame2() ;呵呵,更正楼上的一行:) show一下你要显示的界面就完了嘛或是按找二楼的用setVisible(true)使其可见,都行的 import java.applet.*;import java.awt.*;import java.awt.event.*;class Yourwindow extends Frame{ Yourwindow(String s, int a,int b) //构造方法。 { super(s); //名字是字符串s。 setLayout(new GridLayout(1,1));// 把布局设置为GridLayout布局。 setSize(a,b); //把窗口的初始大小设置为a*b像素。 setBackground(Color.white); //把窗口的底色设置为白色。setVisible(false); //把窗口设置为不可见的。pack();//用紧凑方式显示窗口。 } }public class Example15_2 extends Applet implements ActionListener{ Yourwindow window1,window2 ; //声明两个窗口对象。 Button button1,button2,button3,button4; public void init() { button1=new Button("开南窗"); button2=new Button("开北窗"); button3=new Button("关南窗"); button4=new Button("关北窗"); window1=new Yourwindow("阳光之窗",60,60);//创建窗口 window2=new Yourwindow("冰雪之窗",70,70);//创建窗口 button1.addActionListener(this); button2.addActionListener(this); button3.addActionListener(this); button4.addActionListener(this); add(button1);add(button2);add(button3);add(button4); }public void actionPerformed(ActionEvent e) { if(e.getSource()==button1) { window1.setVisible(true); } else if(e.getSource()==button3) { window1.setVisible(false); } else if(e.getSource()==button2) { window2.setVisible(true); } else if(e.getSource()==button4) { window2.setVisible(false); } }} private void ButtonActionPerformed(java.awt.event.ActionEvent evt) { new newFrame().show(); }你只需要这样就可以了,如果要返回到上一级窗口的话就设置如下: private void exitForm(java.awt.event.WindowEvent evt) { setVisible(false); dispose(); } 关于非法盗链的问题! 各位帮帮看个小程序,关于求101到200的质数小毛病 请教这种写法的用意 寻找卿光忠 求助:那为高手可以给我解释一下javabean是什么意思啊? 关于封装 一个放在集合中的类,写的EQUALS,感到一个迷惑,请指教!!! 如题 中文参数的传递 Java Swing问题 在我机子上打开网页可以显示CLASS在其它的机子中为什么不能显示? 监听操作的问题
或是按找二楼的用setVisible(true)使其可见,都行的
import java.awt.*;
import java.awt.event.*;
class Yourwindow extends Frame
{
Yourwindow(String s, int a,int b) //构造方法。
{ super(s); //名字是字符串s。
setLayout(new GridLayout(1,1));// 把布局设置为GridLayout布局。
setSize(a,b); //把窗口的初始大小设置为a*b像素。
setBackground(Color.white); //把窗口的底色设置为白色。
setVisible(false); //把窗口设置为不可见的。
pack();//用紧凑方式显示窗口。
}
}
public class Example15_2 extends Applet implements ActionListener
{ Yourwindow window1,window2 ; //声明两个窗口对象。
Button button1,button2,button3,button4;
public void init()
{ button1=new Button("开南窗"); button2=new Button("开北窗");
button3=new Button("关南窗"); button4=new Button("关北窗");
window1=new Yourwindow("阳光之窗",60,60);//创建窗口
window2=new Yourwindow("冰雪之窗",70,70);//创建窗口
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
button4.addActionListener(this);
add(button1);add(button2);add(button3);add(button4);
}
public void actionPerformed(ActionEvent e)
{ if(e.getSource()==button1)
{ window1.setVisible(true);
}
else if(e.getSource()==button3)
{ window1.setVisible(false);
}
else if(e.getSource()==button2)
{ window2.setVisible(true);
}
else if(e.getSource()==button4)
{ window2.setVisible(false);
}
}
}
new newFrame().show();
}
你只需要这样就可以了,如果要返回到上一级窗口的话就设置如下:
private void exitForm(java.awt.event.WindowEvent evt) {
setVisible(false);
dispose();
}