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

📄 confirmdialog.java

📁 实现JSP开发的BBS源码
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

//交互对话框
public class confirmDialog extends Dialog implements ActionListener{
	private JButton confirm=new JButton("Yes");
	private JButton cancel=new JButton("Cancel");
	private JLabel label=new JLabel("Are you sure ?",SwingConstants.CENTER);
	public boolean isOkay=false;
	private class WindowCloser extends WindowAdapter{
		public void windowClosing(WindowEvent we){
			confirmDialog.this.isOkay=false;
			confirmDialog.this.hide();
		}
	}
	
	//构造方法1
	public confirmDialog(Frame parent){
		this(parent,"Please confirm","Are you sure ?");
	}
	
	//构造方法2
	public confirmDialog(Frame parent,String title,String question){
		super(parent,title,true);
		label.setText(question);
		setup();//初始化面板
		confirm.addActionListener(this);
		cancel.addActionListener(this);
		addWindowListener(new WindowCloser());
		setResizable(false);
		show();
	}
	
	//初始化面板方法
	private void setup(){
		setSize(300,200);
		setLocation(400,400);
		JPanel buttons=new JPanel();
		buttons.add(confirm);
		buttons.add(cancel);
		setLayout(new BorderLayout());
		add("Center",label);
		add("South",buttons);
	}
	
	//事件监听
	public void actionPerformed(ActionEvent ae){
		isOkay=(ae.getSource()==confirm);
		if(isOkay){
			confirmDialog.this.hide();
		}
		else
		  hide();
	}
}

⌨️ 快捷键说明

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