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

📄 confirmdialog.java

📁 java编程开发技巧与实例的编译测试通过的所有例程
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;

public class ConfirmDialog extends Dialog implements ActionListener
{
	private Button okey		=	new Button("Okey");
	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();
		okey.addActionListener(this);
		cancel.addActionListener(this);
		addWindowListener(new WindowCloser());
		setResizable(false);
		pack();
		int x	=	parent.getLocation().x + (parent.getSize().width - getSize().width) / 2;
		int y	=	parent.getLocation().y + (parent.getSize().height - getSize().height) / 2;
		x = Math.min(getToolkit().getScreenSize().width - getSize().width, x);
		y = Math.min(getToolkit().getScreenSize().height - getSize().height, y);
		setLocation(Math.max(0, x), Math.max(0, y));
		show();
	}
	private void setup()
	{
		Panel buttons	=	new Panel();
		buttons.setLayout(new FlowLayout());
		buttons.add(okey);	buttons.add(cancel);
		setLayout(new BorderLayout());
		add("Center", label);	add("South", buttons);
		setLocationRelativeTo(null);
	    //setLocation(300, 300);
	}
	public void actionPerformed(ActionEvent ae)
	{
		isOkay = (ae.getSource() == okey);
		//---------------------- centerilzition ------------------------------------------------------
	    //--------------------------------------------------------------------------------------------
	    
	    //-------method II
		hide();
	}
	
}

⌨️ 快捷键说明

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