⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testdialog.java

📁 Java语言
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
public class TestDialog{
   public static void main(String args[]){
	MyFrame f=new MyFrame("拥有对话框的窗口");
 	f.setVisible(true);
   }
}
class MyFrame extends Frame implements ActionListener{
     Label label1; Panel p1;
    Button btn1,btn2,btn3,btn4;    Dialog dialog;
         public MyFrame(String s){
	 super(s);
	 this.addWindowListener(new WindowAdapter(){
                 public void windowClosing(WindowEvent e){
	          dispose();
		System.exit(0);}});
     setLayout(new GridLayout(2,1));
     setSize(200,200);   pack();
     label1=new Label
               ("单击按钮将弹出或隐藏对话框",Label.CENTER);
     p1=new Panel();
     btn1=new Button("显示对话框");
     btn2=new Button("隐藏对话框");
     btn3=new Button("显示对话框");
     btn4=new Button("隐藏对话框");	   
     btn1.addActionListener(this);
     btn2.addActionListener(this);
      add(label1); add(p1);
      p1.add(btn1); p1.add(btn2);
          dialog=new Dialog(this,"对话框",false);
//      dialog=new Dialog(this,"对话框",true);
           dialog.add(new Label("这是一个对话框"));
           dialog.setLayout(new FlowLayout());
           dialog.setSize(100,200);
//           dialog.add(btn3);
//           dialog.add(btn4);
           dialog.addWindowListener
                                               (new WindowAdapter(){
              public void windowClosing(WindowEvent e){
			dialog.setVisible(false);
	      }});}
 public void actionPerformed(ActionEvent e){
      if(e.getSource()==btn1) 
	dialog.setVisible(true);
      if(e.getSource()==btn2) 
	dialog.setVisible(false);}}

⌨️ 快捷键说明

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