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

📄 mydialog.java

📁 java初学者经典小例子
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;

public class MyDialog implements ActionListener {

  private Frame f;
  private Dialog d;
  private Button db1;
  private Label dl;
  private Button b;

  public void go() {
    f = new Frame("Dialog");

    // Set up dialog.
    d = new Dialog(f, "Dialog1", true);
    d.setLayout(new GridLayout(2,1));
    dl = new Label("Hello, I'm a Dialog");
    db1 = new Button("OK");
    d.add(dl);
    d.add(db1);
    d.pack();

    b = new Button("Launch Dialog");

    // Register listener for buttons.
    b.addActionListener(this);
    db1.addActionListener(this);

    f.add(b, BorderLayout.CENTER);
    f.pack();
    f.setVisible(true);
  }

  // Handler for all buttons.
  public void actionPerformed( ActionEvent ae) {
    String buttonPressed = ae.getActionCommand();
    if (buttonPressed.equals("Launch Dialog")) {
      d.setVisible(true);
    } else if (buttonPressed.equals("OK")) {
      System.out.println ("Process terminated!!!");
      System.exit(0);
    } else {
      d.setVisible(false);
    }
  }

  public static void main (String args[]) {
    MyDialog myDialog = new MyDialog();
    myDialog.go();
  }
}

⌨️ 快捷键说明

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