怎样实现弹出一个已经做好的界面?

smartboy168 2004-07-27 09:10:16
我是初学者。
我想实现一个事件是:
一点了按钮,就会弹出另一个界面。
我在主界面上有个按钮。想弹出另一个界面,这个界面的名是“student”
请问怎么现实这个功能的代码是怎样?我是用Jbulider9.0来搞的
谢谢!!!
怎样在下面的代码里
button.addActionListener(new ActionListener(){
void jButton4_actionPerformed(ActionEvent e){
?????

}
添加我已经建好的另一个界面“Frame2”的实践代码。
谢谢了。

...全文
168 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
820830 2004-07-28
  • 打赏
  • 举报
回复
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);
}
}
}
apple21 2004-07-28
  • 打赏
  • 举报
回复
学习!!
Frank1982 2004-07-28
  • 打赏
  • 举报
回复
private void ButtonActionPerformed(java.awt.event.ActionEvent evt) {
new newFrame().show();
}
你只需要这样就可以了,如果要返回到上一级窗口的话就设置如下:
private void exitForm(java.awt.event.WindowEvent evt) {
setVisible(false);
dispose();
}
nwpulipeng 2004-07-27
  • 打赏
  • 举报
回复
show一下你要显示的界面就完了嘛
或是按找二楼的用setVisible(true)使其可见,都行的
woodyong 2004-07-27
  • 打赏
  • 举报
回复
Frame2 frame = new Frame2() ;

呵呵,更正楼上的一行:)
registered 2004-07-27
  • 打赏
  • 举报
回复
Frame2 frame;

frame.pack();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setVisible(true);

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧