使用showMessageDialog显示消息框
-----------------siwuxie095
工程名:TestJOptionPane
包名:com.siwuxie095.showdialog
类名:TestMessageDialog.java
工程结构目录如下:

代码:
|
package com.siwuxie095.showdialog; import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.border.EmptyBorder; import com.sun.java.swing.plaf.windows.WindowsLookAndFeel; import javax.swing.JButton; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; public class TestMessageDialog extends JFrame { private JPanel contentPane; /** * Launch the application. */ public static EventQueue.invokeLater(new Runnable() { public try { TestMessageDialog frame = new TestMessageDialog(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public TestMessageDialog() { try { UIManager.setLookAndFeel(new WindowsLookAndFeel()); } catch (UnsupportedLookAndFeelException e1) { e1.printStackTrace(); } setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 300); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(0, 0)); setContentPane(contentPane);
JButton btnshowmessagedialog = new JButton("显示消息框(showMessageDialog)"); btnshowmessagedialog.setFocusable(false);
//为 btnshowmessagedialog.addMouseListener(new MouseAdapter() { @Override public
/** * 直接通过静态方法调用 * 需要指定父级窗体,消息,标题,消息类型 * 返回值是 void,即不会向系统返回任何信息 * 即消息框仅仅是为了向用户传达信息 * 没有关闭消息框时,后面的主窗体是完全无法操作的(即 */ JOptionPane.showMessageDialog(TestMessageDialog.this, "NullPointerException","Error", JOptionPane.ERROR_MESSAGE); } }); contentPane.add(btnshowmessagedialog, BorderLayout.NORTH); } } |
将窗体
JFrame 的 LookAndFeel 设定为 Windows
在根面板 contentPane 的上方添加一个 JButton,
将其 focusable 属性设为
false
为 JButton 添加 mouseClicked 事件,点击 按钮 弹出消息框
运行程序:

【made by siwuxie095】
使用showMessageDialog显示消息框的更多相关文章
- 【C#】分享一个可携带附加消息的增强消息框MessageBoxEx
--------------201507160917更新--------------- 无意中发现标准消息框在Windows7是有声音的,只是在Windows server 2008(R2)无声,而我 ...
- 用Javascript弹出div定义的消息框并往块里面填写文字
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Delphi 7中的四种消息框
Delphi中平常使用的消息框有四种形式,有ShowMessage.MessageDlg.Application.MessageBox.MessageBox.下面来深入了解下这四种形式的实现和使用.1 ...
- VBA消息框
MsgBox函数显示一个消息框,并等待用户点击一个按钮,然后根据用户点击该按钮的动作执行. 语法 MsgBox(prompt[,buttons][,title][,helpfile,context]) ...
- 微信小程序API交互反馈,wx.showToast显示消息提示框
导读:wx.showToast(OBJECT) 显示消息提示框. OBJECT参数说明: 参数 类型 必填 说明 最低版本 title String 是 提示的内容 icon String 否 图标, ...
- Android学习笔记通过Toast显示消息提示框
显示消息提示框的步骤 这个很简单我就直接上代码了: Button show = (Button)findViewById(R.id.show); show.setOnClickListener(new ...
- JS_Window-三种消息框:警告框、确认框、提示框、页面显示时间-计时-延时
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="U ...
- 动手动脑及java程序之用消息框进行数的运算
动手动脑 自信成就人生 动手动脑1 ✿仔细阅读示例: EnumTest.java,运行它,分析运行结果? package demo; public class Test { publi ...
- SAP CRM 显示消息/在消息中进行导航
向用户展示消息,在任何软件中都是十分重要的. 在SAP CRM WEB UI中展示消息,不是一项很难的任务,只需要创建消息并在之后调用方法来显示它 消息类和消息号: 我在SE91中创建了如下的消息类和 ...
随机推荐
- Kattis - horrorfilmnight 【贪心】
题意 有两个人想去一起看电影,然后分别给出两个人 分别喜欢看的电影都在哪些天 然后 同一个人 不能连续看两天他不喜欢的电影 求他们最多可以看多少次电影 思路 先将两人喜欢看的电影进行排序, ① 选择两 ...
- 【leetcode刷题笔记】Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height bala ...
- 【leetcode刷题笔记】Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- 剑指offer——圆圈中最后剩下的数字
1.如果通过环形列表去模拟圆圈的话,最后时间复杂度为O(mn),而且还需要一个辅助链表来模拟圆圈,空间复杂度为O(n). 2.通过找出递推公式的方法,求得递推公式为 时间复杂度为O(n),空间复杂度为 ...
- vim 的配置文件(.vimrc)
linux 下面的root的主目录中新建.vimrc配置文件,配置文件注析方式为“,不是#: 如: "显示行号 set number set ruler
- DL二(稀疏自编码器 Sparse Autoencoder)
稀疏自编码器 Sparse Autoencoder 一神经网络(Neural Networks) 1.1 基本术语 神经网络(neural networks) 激活函数(activation func ...
- Html 表单表格 form table
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Java -- 键盘输入 Scanner, BufferedReader。 系统相关System,Runtime。随机数 Randrom。日期操作Calendar
1. Scanner 一个基于正则表达式的文本扫描器,他有多个构造函数,可以从文件,输入流和字符串中解析出基本类型值和字符串值. public class Main { public static v ...
- 大话设计模式--中介者模式 Mediator --C++实现实例
1. 中介者模式: 用一个中介对象来封装一系列的对象交互,中介者使各对象不需要显式地相互引用,从而使其耦合松散,而且可以独立改变他们之间的交互. Mediator的出现减少了各个Colleague的耦 ...
- hdu 5475 线段树
An easy problem Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...