栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java——JOptionPane类信息提示窗口实现

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java——JOptionPane类信息提示窗口实现

我一个总结了八个弹出窗口,分别是普通提示、警告提示、错误提示、基本提示、自定义提示、自定义选择提示、下拉框选择提示、输入框提示,不懂的可以留言╮(╯▽╰)╭
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));// 设置网格布局2×5

		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);
		}

	}

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/931087.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号