1 32 33 package it.businesslogic.ireport.gui; 34 35 import javax.swing.*; 36 40 public class MessageBox { 41 42 44 public static final int OK = 1; 45 46 public static final int OKCANCEL = 2; 47 48 public static final int YESNO = 4; 49 50 public static final int YESNOCANCEL = 8; 51 52 54 public static final int ICONERROR = 16; 55 56 public static final int ICONINFORMATION = 32; 57 58 public static final int ICONQUESTION = 64; 59 60 public static final int ICONWARNING = 128; 61 62 63 public MessageBox() { 64 } 65 66 public static int show(String msg, String title, int flags) 67 { 68 return MessageBox.show(null, msg,title,flags); 69 } 70 71 public static int show(String msg) 72 { 73 return MessageBox.show(null, msg,"",MessageBox.OK); 74 } 75 76 public static int show(JComponent parent, String msg) 77 { 78 return MessageBox.show(parent, msg,"",MessageBox.OK); 79 } 80 81 public static int show(JComponent parent, String msg, String title, int flags) 82 { 83 84 int messageType = JOptionPane.PLAIN_MESSAGE; 85 if ( (flags & MessageBox.ICONERROR) != 0) 86 messageType = JOptionPane.ERROR_MESSAGE; 87 else if ( (flags & MessageBox.ICONINFORMATION) != 0) 88 messageType = JOptionPane.INFORMATION_MESSAGE; 89 else if ( (flags & MessageBox.ICONQUESTION) != 0) 90 messageType = JOptionPane.QUESTION_MESSAGE; 91 else if ( (flags & MessageBox.ICONWARNING) != 0) 92 messageType = JOptionPane.WARNING_MESSAGE; 93 94 int buttonType = JOptionPane.DEFAULT_OPTION; 95 if ( (flags & MessageBox.YESNO) != 0) 96 buttonType = JOptionPane.YES_NO_OPTION; 97 else if ( (flags & MessageBox.YESNOCANCEL) != 0) 98 buttonType = JOptionPane.YES_NO_CANCEL_OPTION; 99 else if ( (flags & MessageBox.OKCANCEL) != 0) 100 buttonType = JOptionPane.OK_CANCEL_OPTION; 101 102 return JOptionPane.showConfirmDialog( parent,msg,title,buttonType, messageType); 103 } 104 } 105 | Popular Tags |