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

📄 dialogexam.java

📁 Java程序设计实用教程源代码 本书源代码按章分别放置在不同的文件夹中,所有程序均在JDK1.6环境下编译运行正常,除了第13章需要建立ODBC数据源之外,其他程序只要有Java运行环境即可直接运行
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
public class dialogExam {
  Button btn1 = new Button("模态对话框");
  Button btn2 = new Button("非模态对话框");
  Frame frame = new Frame("TestDialog");
  Panel panel = new Panel();
  Button btn3 = new Button("确定");
  Dialog dialog = new Dialog(frame, "Dialog Title", true);
  FlowLayout flow = new FlowLayout();
  dialogExam() {
    panel.setLayout(new FlowLayout());
    panel.setBackground(Color.PINK);
    panel.add(btn1);
    panel.add(btn2);
    frame.setLayout(flow);
    frame.add(panel);
    btn1.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        dialog.setModal(true);
        dialog.setTitle("模态对话框");
        dialog.setVisible(true);
      }
    });
    btn2.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        dialog.setModal(false);
        dialog.setTitle("非模态对话框");
        dialog.setVisible(true);
      }
    });
    frame.setBounds(0, 0, 400, 200);
    frame.setVisible(true);
    frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    });
    dialog.setLayout(flow);
    dialog.add(btn3);
    btn3.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        dialog.dispose();
      }
    });
    dialog.setBounds(0, 0, 200, 150);
  }
  public static void main(String args[]) {
    new dialogExam();
  }
}

⌨️ 快捷键说明

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