001 package cn.rolia.learning.swing; 002 import javax.swing.JOptionPane; 003 import javax.swing.ImageIcon; 004 import javax.swing.Icon; 005 public class JOptionPaneDemo 006 { 007 public static void main(String[] args) 008 { 009 Icon icon = new ImageIcon("QQ.png"); 010 // int confirmMessage; 011 Object[] possibleValues = {"First", "Second", "Third"}; 012 // Object inputMessage; 013 014 //----------------------------------------------------------------- 015 // Usage: 016 // method: static String/Object | showInputDialog(Xxx) 017 //----------------------------------------------------------------- 018 019 /*1 020 showInputDialog(Object message); 021 */ 022 //inputMessage = JOptionPane.showInputDialog ("Input a Integer:"); 023 024 025 026 /*2 027 showInputDialog(Object message, Object initialSelectionValue) 028 */ 029 // inputMessage = JOptionPane.showInputDialog ("message", new Integer(100)); 030 031 032 033 /*3 034 showInputDialog(Component parentComponent, Object message); 035 */ 036 // inputMessage = JOptionPane.showInputDialog(null,"Input a Integer:"); 037 038 039 040 /*4 041 showInputDialog(Component praentComponent, Object message, Object inintialSelectionValue); 042 */ 043 // inputMessage = JOptionPane.showInputDialog(null, "hello", possibleValues[0]); 044 045 046 047 /*5 048 showInputDialog(Component parentComponent, Object message, 049 String title, int messageType) 050 */ 051 /* inputMessage = JOptionPane.showInputDialog (null, "Input your name please:", 052 "showInputDialog", JOptionPane.PLAIN_MESSAGE); 053 */ 054 055 056 /*6 057 showInputDialog(Component parentComponent, Object message, 058 String title, int messageType, 059 Icon icon, Object[] selectionValues, 060 Object initialSelectionValue); 061 notice:this method return an Object class, not String; 062 */ 063 /* inputMessage = JOptionPane.showInputDialog (null, "Order", "order", JOptionPane.ERROR_MESSAGE, 064 icon,possibleValues, 065 possibleValues[0]); 066 */ 067 068 069 /* 070 Default: 071 parentComponent:null 072 message:"输入" 073 messageType:JOptionPane.QUESTION_MESSAGE 074 optionType:OK_CANCEL_OPTION 075 */ 076 077 078 079 //------------------------------------------------------- 080 // Usage: 081 // method: static int showConformDialog(Xxx) 082 //------------------------------------------------------- 083 084 /*1 085 showConfirmDialog(Component parentComponent, Object message) 086 */ 087 // confirmMessage = JOptionPane.showConfirmDialog (null, "Are you sure?"); 088 089 090 091 /*2 092 showConfirmDialog(Component parentComponent, Object message, String title, 093 int optionType) 094 */ 095 // JOptionPane.showConfirmDialog (null, "Are you sure?", "Comfirm Dialog",JOptionPane.YES_NO_OPTION); 096 097 098 099 /*3 100 showConfirmDialog(Component parentComponent, Object message, String title, 101 int optionType, int messageType) 102 */ 103 // JOptionPane.showConfirmDialog(null, "Are you sure?", "Confirm Dialog", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); 104 105 106 107 /*4 108 showConfirmDialog(Component parentComponent, Object message, String title, 109 int optionType, int messageType, Icon icon) 110 */ 111 // JOptionPane.showConfirmDialog (null, "Are you sure?", "Confirm Dialog", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, icon); 112 113 114 115 /* 116 Default: 117 title:选择一个选项 118 messageType:JOptionPane.QUESTION_MESSAGE 119 optionType: JOptionPane.YES_NO_CANCEL_OPTION 120 */ 121 122 123 124 125 //------------------------------------------------------- 126 // Usage: 127 // method:static int showMessageDialog(Xxx) 128 //------------------------------------------------------- 129 130 /*1 131 showMessageDialog(Component parentComponent, Object message) 132 */ 133 // JOptionPane.showMessageDialog(null, "message1"); 134 135 136 137 /*2 138 showMessageDialog(Component parentComponent, Object message, 139 String title, int messageType) 140 */ 141 // JOptionPane.showMessageDialog (null, "message2", "message2", JOptionPane.INFORMATION_MESSAGE); 142 143 144 145 /*3 146 showMessageDialog(Component parentComponent, Object message, 147 String title, int messageType, Icon icon) 148 */ 149 // JOptionPane.showMessageDialog (null, "message3","message3", JOptionPane.PLAIN_MESSAGE,icon); 150 151 /* 152 Default: 153 title:信息 154 messageType:JOptionPane.INFORMATION_MESSAGE 155 optionType:JOptionPane.OK_OPTION 156 */ 157 158 159 160 //----------------------------------------- 161 // Usage: 162 // method:static int | showOptionDialog(Xxx); 163 //----------------------------------------- 164 /*Only 1 165 showOptionDialog(Component parentComponent, Object message, 166 String title, int optionType, int messageType, 167 Icon icon, Object[] options, Object initialValue) 168 */ 169 JOptionPane.showOptionDialog (null, "OptionDialog","OptionDialog", 170 JOptionPane.DEFAULT_OPTION,JOptionPane.WARNING_MESSAGE, 171 icon, possibleValues, possibleValues[0]); 172 173 174 175 176 //---------------------------------------- 177 // Other method 178 //---------------------------------------- 179 180 //JDialog | createDialog(Component parentComponent, String title) 181 182 183 System.exit(0); 184 185 } 186 } |