zoukankan      html  css  js  c++  java
  • JOptionPane用法--java

    JOptionPane用法--java

    JOptionPane的简单应用:

    1.首先引入包:

    import javax.swing.JOptionPane;

    2.添加如下代码:

    Object[] options = {"确定","取消","帮助"};

    //定制可供选择按钮

    int response=JOptionPane.showOptionDialog(null, "这是个选项对话框,用户可以选择自己的按钮的个数","选项对话框标题",JOptionPane.YES_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);

    if(response==0) {        

       JOptionPane.showMessageDialog(null,"您按下了确定按钮","消   息",JOptionPane.INFORMATION_MESSAGE);//消息对话框     

    } else if(response==1) {          

          JOptionPane.showMessageDialog(null,"您按下了取消按钮","消息",JOptionPane.INFORMATION_MESSAGE);      

    } else if(response==2) {        

          JOptionPane.showMessageDialog(null,"您按下了帮助按钮","消息",JOptionPane.INFORMATION_MESSAGE);        

    }               

    String sa=JOptionPane.showInputDialog(null,"请输入第一个整数:"); 

    //输入对话框       

    String sb=JOptionPane.showInputDialog(null,"请输入第二个整数:");       

    int ia,ib;       

    try{    //捕获parselnt()抛出的异常          

      ia=Integer.parseInt(sa);       

    }catch(Exception e){           

       ia=0;       

    }                   

    try{           

      ib=Integer.parseInt(sb);       

    }catch(Exception e){           

      ib=0;       

    }       

    int ic=ib+ia;       

    JOptionPane.showMessageDialog(null,"这两个数之和是:"+ic,"Message",JOptionPane.INFORMATION_MESSAGE);

    简单学习JOptionPane的三种对话框的简单应用,大致了解一下就行了,不是很难,用几次自然就记住了。再者,触类旁通,其余的也不必都练习了,只要用的时候知道大概,再查也不迟。

  • 相关阅读:
    php单元测试
    git配置本地环境(phpstudy/tortoisegit/git等)
    xp/win7中系统安装memcached服务,卸载memcached服务,以及删除memcached服务
    memcached装、启动和卸载
    如何安装memcached
    三元运算符、逻辑运算符
    移动端页面怎么适配ios页面
    javascript正则表达式——元字符
    一个div添加多个背景图片
    GNU Screen使用入门
  • 原文地址:https://www.cnblogs.com/originate918/p/6244945.html
Copyright © 2011-2022 走看看