重要:JOptionPane类提示框的一些常用的方法

来源:互联网 发布:网络部面试问题有哪些 编辑:程序博客网 时间:2024/06/05 00:43

一般都是都在页面做弹出框,如果后台要做弹出框就可以用JOptionPane类,其中封装了很多的方法。


import javax.swing.JOptionPane;

showMessageDialog

 JOptionPane.showMessageDialog(null, "SUCCESS!"); 


 JOptionPane.showMessageDialog(null, "SUCCESS", "TITLE",JOptionPane.PLAIN_MESSAGE);  


 JOptionPane.showMessageDialog(null, "SUCCESS", "TITLE",JOptionPane.WARNING_MESSAGE);  


 JOptionPane.showMessageDialog(null, "ERROR"  , "TITLE",JOptionPane.ERROR_MESSAGE);

showOptionDialog

int n = JOptionPane.showConfirmDialog(null, "DOWN OR NOT", "TITLE",JOptionPane.YES_NO_OPTION);//Y 0 N 1

Object[] options ={ "OH YES!", "NONO!" };
int m = JOptionPane.showOptionDialog(null, "DOWN OR NOT", "TITLE",JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); 

showInoutDialog
Object[] obj2 ={ "RED", "YELLOW", "GREEN" };  
String s = (String) JOptionPane.showInputDialog(null,"WHAT COLOR DO U LIKE?", "COLOR", JOptionPane.PLAIN_MESSAGE, new ImageIcon("icon.png"), obj2, "RED");  
 


0 0