10.20dialogtest.java

来自「JAVA程序设计的源代码」· Java 代码 · 共 29 行

JAVA
29
字号
import java.awt.*;
import java.awt.event.*;
public class DialogTest extends Frame implements ActionListener{
Frame f;
Dialog d;
Button b;
Label l;
public void go(){
f = new Frame ("对话框");
d = new Dialog (f, "ok", false);    //创建一个对话框
b = new Button ("ok");
l = new Label ("Welcome to come!");
f.setBounds(200,200,200,200);    //设置版面显示区域
f.add ("Center",b);    
d.add ("Center",l);
d.setBounds(300,300,150,100);    //设置对话框显示区域
b.addActionListener (this);    //设置事件监听
f.setVisible (true);    //设置面板可见
}
public void actionPerformed (ActionEvent e){    //事件处理函数
//按下f上的按钮时
d. setVisible (true);    //设置对话框可见
}
public static void main (String args[]){
DialogTest e=new DialogTest();
e.go();
}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?