java标准对话框JOptionPane的简单设计
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class JOptionPane implements ActionListener {
JFrame frame = null;
JPanel panel =null;
JRadioButton buttonMessage = null;
JRadioButton buttonConfirm = null;
JRadioButton buttonOption = null;
JRadioButton buttonInput = null;
JOptionPane(){
frame = new JFrame("对话框");
panel = new JPanel();
buttonMessage = new JRadioButton("Message");
buttonConfirm = new JRadioButton("Confirm");
buttonOption = new JRadioButton("Option");
buttonInput = new JRadioButton("Input");
frame.add(panel);
panel.add(buttonMessage);
panel.add(buttonConfirm);
panel.add(buttonOption);
panel.add(buttonInput);
buttonMessage.addActionListener(this);
buttonConfirm.addActionListener(this);
buttonOption.addActionListener(this);
buttonInput.addActionListener(this);
frame.setSize(400,200);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == buttonMessage) {
JOptionPane.showMessageDialog(frame, "添加数据成功", "消息对话框", JOptionPane.INFORMATION_MESSAGE);
} else if (e.getSource() == buttonConfirm) {
JOptionPane.showConfirmDialog(frame, "是否删除这些数据", "确认对话框", JOptionPane.WARNING_MESSAGE);
} else if (e.getSource() == buttonOption) {
Object[] option = {"保存", "不保存", "取消"};
JOptionPane.showOptionDialog(frame, "是否保存这些数据", "确认对话框", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, option, option[0]);
} else if (e.getSource() == buttonInput) {
JOptionPane.showInputDialog(frame,"请输入要保存的数据","输入对话框",JOptionPane.QUESTION_MESSAGE);
}
}
public static void main(String[] args) {
new JOptionPane();
}
}