我一个总结了八个弹出窗口,分别是普通提示、警告提示、错误提示、基本提示、自定义提示、自定义选择提示、下拉框选择提示、输入框提示,不懂的可以留言╮(╯▽╰)╭
package wyg;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.*;
import javax.swing.*;
public class s extends JFrame implements ActionListener {
private JButton JB1, JB2, JB3, JB4, JB5, JB6, JB7, JB8;
public void ddd() {
this.setSize(500, 250);
this.setLocationRelativeTo(null);
JPanel JP = new JPanel();
JP.setLayout(new GridLayout(2, 4));
JB1 = new JButton("普通提示");
JP.add(JB1);
JB2 = new JButton("警告提示");
JP.add(JB2);
JB3 = new JButton("错误提示");
JP.add(JB3);
JB4 = new JButton("基本提示");
JP.add(JB4);
JB5 = new JButton("自定义提示");
JP.add(JB5);
JB6 = new JButton("自定义选择");
JP.add(JB6);
JB7 = new JButton("下拉框选择");
JP.add(JB7);
JB8 = new JButton("输入框");
JP.add(JB8);
this.setDefaultCloseOperation(3);
this.add(JP);
this.setVisible(true);
JB1.addActionListener(this);
JB2.addActionListener(this);
JB3.addActionListener(this);
JB4.addActionListener(this);
JB5.addActionListener(this);
JB6.addActionListener(this);
JB7.addActionListener(this);
JB8.addActionListener(this);
}
public static void main(String[] args) {
s a = new s();
a.ddd();
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == JB1) {
JOptionPane.showMessageDialog(null, "我是普通提示框!");
}
if (e.getSource() == JB2) {
JOptionPane.showMessageDialog(null, "我是警告提示框!", "我是警告提示", JOptionPane.WARNING_MESSAGE);
}
if (e.getSource() == JB3) {
JOptionPane.showMessageDialog(null, "我是错误提示框!", "我是错误提示", JOptionPane.ERROR_MESSAGE);
}
if (e.getSource() == JB4) {
JOptionPane.showMessageDialog(null, "我是最基本提示框!", "我是最基本提示", JOptionPane.PLAIN_MESSAGE);
}
if (e.getSource() == JB5) {
JOptionPane.showConfirmDialog(null, "我是自定义提示框!", "我是自定义提示", JOptionPane.YES_NO_OPTION);
}
if (e.getSource() == JB6) {
Object[] a = { "第一个", "第二个", "第三个" };
JOptionPane.showOptionDialog(null, "你选了哪个选项?", "我是自定义选择", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null, a, a[0]);
}
if (e.getSource() == JB7) {
Object[] a = { "西瓜", "哈密瓜", "倭瓜" };
JOptionPane.showInputDialog(null, "请选择一个瓜:\n", "我是下拉框选择", JOptionPane.PLAIN_MESSAGE,
new ImageIcon("显示的图片路径,没有也可"), a, "");
}
if (e.getSource() == JB8) {
JOptionPane.showInputDialog(null, "请输入密码:╮(╯▽╰)╭\n", "我是输入框", JOptionPane.PLAIN_MESSAGE);
}
}
}