confirmdialog.java

来自「Java程序设计技巧与开发实例附书源代码。」· Java 代码 · 共 40 行

JAVA
40
字号
import java.awt.*;import java.awt.event.*;public class ConfirmDialog extends Dialog implements ActionListener{  private Button okay = new Button("确定");   private Button cancel = new Button("取消");   private Label  label = new Label("Are you sure?",Label.CENTER);   public  boolean isOkay = false;   private class WindowCloser extends WindowAdapter   {  public void windowClosing(WindowEvent we)      {  ConfirmDialog.this.isOkay = false;         ConfirmDialog.this.hide();      }   }   public ConfirmDialog(Frame parent)   {  this(parent,"Please confirm","Are you sure?"); }   public ConfirmDialog(Frame parent,String title,String question)   {  super(parent,title,true);      label.setText(question);      setup();      okay.addActionListener(this);      cancel.addActionListener(this);      addWindowListener(new WindowCloser());      setResizable(false);      pack(); show();   }   private void setup()   {  Panel buttons = new Panel();      buttons.setLayout(new FlowLayout());      buttons.add(okay); buttons.add(cancel);      setLayout(new BorderLayout());      add("Center",label);  add("South",buttons);   }   public void actionPerformed(ActionEvent ae)   {  isOkay = (ae.getSource() == okay);      hide();   }}

⌨️ 快捷键说明

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