javax.swing.JOptionPane.showMessageDialog() 方法
来源:互联网 发布:php 大端 编辑:程序博客网 时间:2024/06/06 14:17
import javax.swing.JOptionPane;
Java 8 api:
1.
public static void showMessageDialog(Component parentComponent,
Object message)
throws HeadlessException
Brings up an information-message dialog titled "Message".
Parameters:
parentComponent - determines the Frame in which the dialog is displayed; if null, or if the parentComponent has no Frame, a default Frame is used
message - the Object to display
Throws:
HeadlessException - if GraphicsEnvironment.isHeadless returns true
2.
public static void showMessageDialog(Component parentComponent,
Object message,
String title,
int messageType)
throws HeadlessException
Brings up a dialog that displays a message using a default icon determined by the messageType parameter.
Parameters:
parentComponent - determines the Frame in which the dialog is displayed; if null, or if the parentComponent has no Frame, a default Frame is used
message - the Object to display
title - the title string for the dialog
messageType - the type of message to be displayed: ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE
Throws:
HeadlessException - if GraphicsEnvironment.isHeadless returns true
3.
public static void showMessageDialog(Component parentComponent,
Object message,
String title,
int messageType,
Icon icon)
throws HeadlessException
source code:
import java.awt.Container;import java.awt.FlowLayout;import java.awt.Font;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JOptionPane;public class JOptionPaneDemo extends JFrame implements ActionListener{private JButton buttons[];private String names[] = {"show the first function","show the error message dialog","show the information message dialog","show the warning message dialog","show the question message dialog","show the plain message dialog","show the message dialog with icon"};private Container container;Font font = new Font("Times New Roman", Font.PLAIN, 20);ImageIcon bug = new ImageIcon("C:/Users/10653/Desktop/java.png");public JOptionPaneDemo(){super("JOptionPaneDemo");container = getContentPane();container.setLayout(new FlowLayout());buttons = new JButton[names.length];for(int count = 0; count < names.length; count++){buttons[count] = new JButton(names[count]);buttons[count].setFont(font);buttons[count].addActionListener(this);container.add(buttons[count]);}setSize(800, 600);setVisible(true);}public void actionPerformed(ActionEvent event){String string = event.getActionCommand();if(string == "show the first function")JOptionPane.showMessageDialog(new JFrame(), "message");if(string == "show the error message dialog")JOptionPane.showMessageDialog(new JFrame(), "error message", "error", JOptionPane.ERROR_MESSAGE);if(string == "show the information message dialog")JOptionPane.showMessageDialog(new JFrame(), "information message", "information", JOptionPane.INFORMATION_MESSAGE);if(string == "show the warning message dialog")JOptionPane.showMessageDialog(new JFrame(), "warning message", "warning", JOptionPane.WARNING_MESSAGE);if(string == "show the question message dialog")JOptionPane.showMessageDialog(new JFrame(), "question message", "question", JOptionPane.QUESTION_MESSAGE);if(string == "show the plain message dialog")JOptionPane.showMessageDialog(new JFrame(), "plain message", "plain", JOptionPane.PLAIN_MESSAGE);if(string == "show the message dialog with icon")JOptionPane.showMessageDialog(new JFrame(), "message with icon", "message", JOptionPane.INFORMATION_MESSAGE, bug);}public static void main(String srgs[]){JOptionPaneDemo application = new JOptionPaneDemo();application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}}
pictures of the results:
JOptionPane.showMessageDialog(new JFrame(), "message")
JOptionPane.showMessageDialog(new JFrame(), "error message", "error", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(new JFrame(), "information message", "information", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(new JFrame(), "warning message", "warning", JOptionPane.WARNING_MESSAGE);
JOptionPane.showMessageDialog(new JFrame(), "question message", "question", JOptionPane.QUESTION_MESSAGE);
JOptionPane.showMessageDialog(new JFrame(), "plain message", "plain", JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(new JFrame(), "message with icon", "message", JOptionPane.INFORMATION_MESSAGE, bug);
tips:when brings up the message dialog by custom icon, parameter "messageType" doesn't influence the display effect. That is, whether you use "PLAIN_MESSAGE" or "ERROR_MESSAGE" or other parameters for “messageType” when you use the third override function, the display effects are same.
- javax.swing.JOptionPane.showMessageDialog() 方法
- javax.swing.JOptionPane.showMessageDialog() 方法
- javax.swing.JOptionPane.showMessageDialog() 方法
- javax.swing.JOptionPane.showMessageDialog() 方法
- javax.swing.JOptionPane 类的 showConfirmDialog 方法
- Java javax.swing.JOptionPane包
- import javax.swing.JOptionPane的问题
- JOptionPane.showMessageDialog的使用
- JOptionPane.showInputDialog & JOptionPane.showConfirmDialog & showMessageDialog的应用
- 弹出警告对话框JOptionPane.showMessageDialog
- Java 项目无法引用javax.swing.JOptionPane JAVA引用JOptionPane类报错 解决方案
- java学习笔记之swing.JOptionPane方法
- 做swing程序中遇到使用消息提示框的,JOptionPane类其中封装了很多的方法。 很方便的,于是就简单的整理了一下。 1.1 showMessageDialog 显示一个带有OK 按钮的模态
- Swing 写的客户端程序在java web start 运行,多语言过程中,JOptionPane.showMessageDialog() 按钮多语言问题
- javax.swing super()方法
- JOptionPane.showMessageDialog(null," ")中的null 含义
- Swing-对话框-JOptionPane
- javax.swing
- Submission Details
- 线程的数据共享和不共享
- 数学建模之美赛小总结
- Android访问修饰符的区别
- 计算机视觉
- javax.swing.JOptionPane.showMessageDialog() 方法
- opencv3+版本感觉还是不稳定啊
- 线程安全
- com.android.ddmlib.AdbCommandRejectedException: device offline
- Ubuntu更新源
- HTML中嵌入css的三种方式
- 递归(2)
- 线程的各种函数
- 使用pyinstaller过程中遇到的一些问题