JOptionPane

JOptionPaneDemo.java
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 }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值