正文

JOptionPane用法2005-09-17 01:07:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/hurongliang/4852.html

分享到:

package hu.demos;
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;
import javax.swing.Icon;
public class JOptionPaneDemo
{
 public static void main(String[] args)
 {
  Icon icon = new ImageIcon("QQ.png");
  int confirmMessage;
  Object[] possibleValues = {"First", "Second", "Third"};
  Object inputMessage;
  
  //-----------------------------------------------------------------
  // Usage:
  // method: static String/Object | showInputDialog(Xxx)
  //-----------------------------------------------------------------  
  
  /*1
  showInputDialog(Object message);
  */
//  inputMessage = JOptionPane.showInputDialog ("Input a Integer:");
  
  
  
  /*2
  showInputDialog(Object message, Object initialSelectionValue)
  */
//  inputMessage = JOptionPane.showInputDialog ("message", new Integer(100));
  
  
  
  /*3
  showInputDialog(Component parentComponent, Object message);
  */
//  inputMessage = JOptionPane.showInputDialog(null,"Input a Integer:");
  
  
  
  /*4
  showInputDialog(Component praentComponent, Object message, Object inintialSelectionValue);
  */
//  inputMessage = JOptionPane.showInputDialog(null, "hello", possibleValues[0]);


  
  /*5
  showInputDialog(Component parentComponent, Object message,
          String title, int messageType)
  */
/*  inputMessage = JOptionPane.showInputDialog (null, "Input your name please:",
          "showInputDialog", JOptionPane.PLAIN_MESSAGE);
*/  
  
  
  /*6
  showInputDialog(Component parentComponent, Object message,
          String title, int messageType,
          Icon icon, Object[] selectionValues,
          Object initialSelectionValue);
  notice:this method return an Object class, not String;
  */
/*  inputMessage = JOptionPane.showInputDialog (null, "Order", "order", JOptionPane.ERROR_MESSAGE,
          icon,possibleValues,
          possibleValues[0]);
*/  
  
  
  /*
  Default:
   parentComponent:null
   message:"输入"
   messageType:JOptionPane.QUESTION_MESSAGE
   optionType:OK_CANCEL_OPTION
  */
  
  
  
  //-------------------------------------------------------
  // Usage:
  // method: static int showConformDialog(Xxx)
  //-------------------------------------------------------
  
  /*1
  showConfirmDialog(Component parentComponent, Object message)
  */
//  confirmMessage = JOptionPane.showConfirmDialog (null, "Are you sure?");
  
  
  
  /*2
  showConfirmDialog(Component parentComponent, Object message, String title,
        int optionType)
  */
//  JOptionPane.showConfirmDialog (null, "Are you sure?", "Comfirm Dialog",JOptionPane.YES_NO_OPTION);
  
  
  
  /*3
  showConfirmDialog(Component parentComponent, Object message, String title,
       int optionType, int messageType)
  */
//  JOptionPane.showConfirmDialog(null, "Are you sure?", "Confirm Dialog", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);  
  
  
  
  /*4
  showConfirmDialog(Component parentComponent, Object message, String title,
       int optionType, int messageType, Icon icon)
  */
//  JOptionPane.showConfirmDialog (null, "Are you sure?", "Confirm Dialog", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, icon);
  
  
  
  /*
  Default:
   title:选择一个选项
   messageType:JOptionPane.QUESTION_MESSAGE
   optionType: JOptionPane.YES_NO_CANCEL_OPTION
  */
  
  
  
  
  //-------------------------------------------------------
  // Usage:
  // method:static int showMessageDialog(Xxx)
  //-------------------------------------------------------
  
  /*1
  showMessageDialog(Component parentComponent, Object message)
  */
//  JOptionPane.showMessageDialog(null, "message1");
  
  
  
  /*2
  showMessageDialog(Component parentComponent, Object message,
       String title, int messageType)
  */
//  JOptionPane.showMessageDialog (null, "message2", "message2", JOptionPane.INFORMATION_MESSAGE);
  
  
  
  /*3
  showMessageDialog(Component parentComponent, Object message,
       String title, int messageType, Icon icon)
  */
//  JOptionPane.showMessageDialog (null, "message3","message3", JOptionPane.PLAIN_MESSAGE,icon);
          
  /*
  Default:
   title:信息
   messageType:JOptionPane.INFORMATION_MESSAGE
   optionType:JOptionPane.OK_OPTION
  */
  
  
  
  //-----------------------------------------
  // Usage:
  // method:static int | showOptionDialog(Xxx);
  //-----------------------------------------
  /*Only 1
  showOptionDialog(Component parentComponent, Object message,
      String title, int optionType, int messageType,
      Icon icon, Object[] options, Object initialValue)
  */
  JOptionPane.showOptionDialog (null, "OptionDialog","OptionDialog",
         JOptionPane.DEFAULT_OPTION,JOptionPane.WARNING_MESSAGE,
         icon, possibleValues, possibleValues[0]);

  
  
  
  //----------------------------------------
  // Other method
  //----------------------------------------
  
  //JDialog | createDialog(Component parentComponent, String title) 
  

  System.exit(0);

 }
}

阅读(12967) | 评论(3)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

loading...
您需要登录后才能评论,请 登录 或者 注册