testdialog.java

来自「这是一个java程序」· Java 代码 · 共 55 行

JAVA
55
字号
//演示对话框Dialog的使用
import java.awt.*; 
import java.awt.event.*;
public class TestDialog{
	TextField tf = new TextField(10);
	Button b1=new Button("模态显示");
	Button b2=new Button("非模态显示");
	Frame f=new Frame("TestDialog");
	

	Button b3=new Button("确定");
    Dialog dlg = new Dialog(f, "Dialog Title", true);
    FlowLayout fl=new FlowLayout();
	TestDialog(){
		f.setLayout(fl);
		f.add(tf);
		f.add(b1);
		f.add(b2);
		b1.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				dlg.setModal(true);
				dlg.setVisible(true);
				tf.setText("www.it315.org");
			}
		});
		b2.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				dlg.setModal(false);
				dlg.setVisible(true);
				tf.setText("www.it315.org");
			}
		});	
		f.setBounds(0,0,400,200);
		f.setVisible(true);
		f.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e){
				System.exit(0);
			}
		});
		dlg.setLayout(fl);
		dlg.add(b3);
		b3.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				dlg.dispose();
			}
		});
	
		dlg.setBounds(0,0,200,150);
			
	}
	public static void main(String[] args){
		new TestDialog();		
	}
}

⌨️ 快捷键说明

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