zoukankan      html  css  js  c++  java
  • 2020.10.02

    一、今日学习内容

       Addition.java

           JoptionPane类的使用:

       1、属于javax.swing 包。

       2、功能:定制四种不同种类的标准对话框。

                         ConfirmDialog 确认对话框。提出问题,然后由用户自己来确认(按"Yes"或"No"按钮)

                         InputDialog 提示输入文本

                         MessageDialog 显示信息

                         OptionDialog 组合其它三个对话框类型。

        3、这四个对话框可以采用showXXXDialog()来显示。如:

                 showConfirmDialog() 显示确认对话框、

                 showInputDialog() 显示输入文本对话框、

                 showMessageDialog() 显示信息对话框、

                 showOptionDialog() 显示选择性的对话框。

        4、参数说明。  

    (1)ParentComponent:指示对话框的父窗口对象,一般为当前窗口。也可以为null即采用缺省的Frame作为父窗口,此时对话框将设置在屏幕的正中。

     (2)message:指示要在对话框内显示的描述性的文字
     (3)String title:标题条文字串。
     (4)Component:在对话框内要显示的组件(如按钮)
     (5)Icon:在对话框内要显示的图标
     (6)messageType(图标):ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE、PLAIN_MESSAGE、

     (7)optionType:对话框底部显示的按钮选项。

              DEFAULT_OPTION、YES_NO_OPTION、YES_NO_CANCEL_OPTION、OK_CANCEL_OPTION。

         5、使用实例:

         (1) 显示MessageDialog

               JOptionPane.showMessageDialog( null , "要显示的信息内容" ,"标题" , JOptionPane.ERROR_MESSAGE) ;

        (2) 显示ConfirmDialog

               JOptionPane.showConfirmDialog( null , "message" , "标题", OptionPane.YES_NO_OPTION )

        (3) 显示OptionDialog:

                该种对话框可以由用户自己来设置各个按钮的个数并返回用户点击各个按钮的序号(从0开始计数)

                 Object[] options = {"查询","存款","取款","退出"};

              int response=JOptionPane.showOptionDialog ( null, " 选择业务类型","ATM 取款机",JOptionPane.YES_OPTION ,JOptionPane.PLAIN_MESSAGE,

              null, options, options[0] ) ;

      if (response == 0)

     {JOptionPane.showMessageDialog(null,"您按下了查询按钮");}

     else if(response == 1)

     {JOptionPane.showMessageDialog(null,"您按下了存款按钮");}

     else if(response == 2)

     {JOptionPane.showMessageDialog(null,"您按下了取款按钮");}

     else if(response == 3)

     {JOptionPane.showMessageDialog(null,"您按下了退出按钮");}

    (4) 显示InputDialog 以便让用户进行输入

    String inputValue = JOptionPane.showInputDialog("Please input a value");

    (5) 显示InputDialog 以便让用户进行选择地输入

     Object[] possibleValues = { "First", "Second", "Third" } ;

     //用户的选择项目

     Object selectedValue = JOptionPane.showInputDialog(null,

     "Choose one", "Input", JOptionPane.INFORMATION_MESSAGE ,

     null, possibleValues , possibleValues[0]);

     setTitle (" 您按下了 " + (String)selectedValue+"项目") ;}

     1 package ceshi;
     2 // An addition program 
     3 
     4 import javax.swing.JOptionPane;  // import class JOptionPane
     5 
     6 public class Addition {
     7    public static void main( String args[] )
     8    {
     9       String firstNumber,   // first string entered by user
    10              secondNumber;  // second string entered by user
    11       int number1,          // first number to add
    12           number2,          // second number to add
    13           sum;              // sum of number1 and number2
    14 
    15       // read in first number from user as a string
    16       firstNumber =
    17          JOptionPane.showInputDialog( "Enter first integer" );
    18 
    19       // read in second number from user as a string
    20       secondNumber =
    21          JOptionPane.showInputDialog( "Enter second integer" );
    22 
    23       // convert numbers from type String to type int
    24       number1 = Integer.parseInt( firstNumber ); 
    25       number2 = Integer.parseInt( secondNumber );
    26 
    27       // add the numbers
    28       sum = number1 + number2;
    29 
    30       // display the results
    31       JOptionPane.showMessageDialog(
    32          null, "The sum is " + sum, "Results",
    33          JOptionPane.PLAIN_MESSAGE );
    34 
    35       System.exit( 0 );   // terminate the program
    36    }
    37 }

             

    二、遇到的问题

       对JoptionPane类的用法不会

    三、明日计划

       继续相关验证

  • 相关阅读:
    双网卡绑定一个IP--bond
    查看window系统电脑连接过的wifi密码
    python字符串
    三级菜单
    购物车
    登录接口
    Python 基础之在ubuntu系统下安装双版本python
    SSH连接linux时,长时间不操作就断开的解决方案
    python中变量None的
    查找文件工具find
  • 原文地址:https://www.cnblogs.com/wmdww/p/13762738.html
Copyright © 2011-2022 走看看