confirmdialog.java
来自「java语言与面向对象程序设计源程序」· Java 代码 · 共 39 行
JAVA
39 行
import java.awt.*;
import java.awt.event.*;
public class ConfirmDialog extends Dialog implements ActionListener
{ private Button okay = new Button("Okay");
private Button cancel = new Button("Cancel");
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 + -
显示快捷键?