我们使用javaSwing的时候会经常使用到一些弹出框,下面我把一些常用的弹出框整理了一个工具类,拿来即用的。
/**
* Date: 2020/5/20 17:07
* Copyright (c) 2020,All Rights Reserved.
*/
package *****;
import javax.swing.*;
import java.awt.*;
/**
* @Author: zhangjun
* @Description:
* @Date: Create in 17:07 2020/5/20
*/
public class MessageDialog {
/** Return value from class method if YES is chosen. */
public static final int YES_OPTION = JOptionPane.YES_OPTION;
/** Return value from class method if NO is chosen. */
public static final int NO_OPTION = JOptionPane.NO_OPTION;
/** Return value from class method if CANCEL is chosen. */
public static final int CANCEL_OPTION = JOptionPane.CANCEL_OPTION;
/** Return value form class method if OK is chosen. */
public static final int OK_OPTION = JOptionPane.OK_OPTION;
/** Return value from class method if user closes window without selecting
* anything, more than likely this should be treated as either a
* <code>CANCEL_OPTION</code> or <code>NO_OPTION</code>. */
public static final int CLOSED_OPTION = JOptionPane.CLOSED_OPTION;
static {
}
private final static String title = "系统提示";
public static void show_OK(Component parent, String message){
JOptionPane.showMessageDialog(parent,message,title,JOptionPane.INFORMATION_MESSAGE);
}
public static int show_OK_CANCEL(Component parent, String message){
return JOptionPane.showConfirmDialog(parent,message,title,JOptionPane.OK_CANCEL_OPTION);
}
public static int show_YES_NO_CANCEL(Component parent,String message){
return JOptionPane.showConfirmDialog(parent,message,title,JOptionPane.YES_NO_OPTION);
}
public static int show_YES_NO(Component parent,String message){
return JOptionPane.showConfirmDialog(parent,message,title,JOptionPane.YES_NO_OPTION);
}
public static void show_Error(Component parent,String message){
JOptionPane.showMessageDialog(parent,message,title,JOptionPane.WARNING_MESSAGE );
}
public static void show_WARNING(Component parent,String message){
JOptionPane.showMessageDialog(parent,message,title,JOptionPane.ERROR_MESSAGE);
}
public static int show_Default(Component parent,String message){
return JOptionPane.showConfirmDialog(parent,message,title,JOptionPane.DEFAULT_OPTION);
}
public static void main(String[] args) {
MessageDialog.show_OK(null,"哈哈,超简单的啦");
}
}
使用效果