JOptionPane.showInputDialog这个用法为啥会报c 空指针针!!

Access denied | www.roseindia.net used Cloudflare to restrict access
Please enable cookies.
What happened?
The owner of this website (www.roseindia.net) has banned your access based on your browser's signature (3d5eebf48f1d1ecb-ua98).在JAVA JOptionPane.showInputDialog();_百度知道
在JAVA JOptionPane.showInputDialog();
输入框,如果用户选择“取消”或干脆关闭他们应该做些什么JAVA JOptionPane.showInputDialog()
我有更好的答案
parselnt()的用法在下一篇
ia=Integer1.首先引入包:import javax:&quot.JOptionP简单学习JOptionPane的三种对话框的简单应用,大致了解一下就行了,不是很难;
int ic=ib+ia.showInputDialog(null,&请输入第二个整数;这是个选项对话框,用户可以选择自己的按钮的个数&,&quot,JOptionP
int ia,ib.QUESTION_MESSAGE, null,);
ib=I选项对话框标题&.parseInt(sb);
}catch(Exception e){
ib=0;/消息对话框
else if(response==1)
JOptionPane.showMessageDialog(,JOptionPane.INFORMATION_MESSAGE).INFORMATION_MESSAGE);
else if(response==2)
JOptionPane.showMessageDialog(null.showMessageDialog(null,&这两个数之和是:&+ic,&Message&quot,&quot.swing,再查也不迟;您按下了帮助按钮&取消&quot,用几次自然就记住了;,&消息&,&,&帮助&}; //您按下了取消按钮&quot,JOptionPane:&定制可供选择按钮int response=JOptionPane.showOptionDialog(null, &quot.添加如下代码:Object[] options = {&确定&.INFORMATION_MESSAGE);&#47.YES_OPTION, JOptionP捕获parselnt()抛出的异常;2,JOptionP).INFORMATION_MESSAGE);
String sa=JOptionP
/&#47.showInputDialog(null,&请输入第一个整数;/输入对话框
String sb=JOptionP
&#47。再者,触类旁通,JOptionPane, options[0]); if(response==0) {
JOptionPane,其余的也不必都练习了,只要用的时候知道大概,&quot.parseInt(sa);
}catch(Exception e){
ia=0.showMessageDialog(null,&您按下了确定按钮&;
JOptionP消
息&;,&消息&,&quot
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。下次自动登录
现在的位置:
& 综合 & 正文
JOptionPane 提示框的用法
最近在做swing程序中遇到使用消息提示框的,JOptionPane类其中封装了很多的方法。
很方便的,于是就简单的整理了一下。
1.1 showMessageDialog
显示一个带有OK 按钮的模态对话框。
下面是几个使用showMessageDialog 的例子:
JOptionPane.showMessageDialog(null, "友情提示");
JOptionPane.showMessageDialog(null, "友情提示");
效果如下:
JOptionPane.showMessageDialog(jPanel, "提示消息", "标题",JOptionPane.WARNING_MESSAGE);
JOptionPane.showMessageDialog(jPanel, "提示消息", "标题",JOptionPane.WARNING_MESSAGE);
效果如下:
JOptionPane.showMessageDialog(null, "提示消息.", "标题",JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null, "提示消息.", "标题",JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null, "提示消息.", "标题",JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null, "提示消息.", "标题",JOptionPane.PLAIN_MESSAGE);
1.2 showOptionDialog
这个函数可以改变显示在按钮上的文字。你还可以执行更多的个性化操作。
常规的消息框:
int n = JOptionPane.showConfirmDialog(null, "你高兴吗?", "标题",JOptionPane.YES_NO_OPTION);//i=0/1
int n = JOptionPane.showConfirmDialog(null, "你高兴吗?", "标题",JOptionPane.YES_NO_OPTION);//i=0/1
效果如下:
个性话消息框:
Object[] options ={ "好啊!", "去一边!" };
int m = JOptionPane.showOptionDialog(null, "我可以约你吗?", "标题",JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
Object[] options ={ "好啊!", "去一边!" };int m = JOptionPane.showOptionDialog(null, "我可以约你吗?", "标题",JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
效果如下:
showInoutDialog
该方法返回一个Object 类型。这个Object 类型一般是一个String 类型,反应了用户的输入。
下拉列表形式的例子:
Object[] obj2 ={ "足球", "篮球", "乒乓球" };
String s = (String) JOptionPane.showInputDialog(null,"请选择你的爱好:\n", "爱好", JOptionPane.PLAIN_MESSAGE, new ImageIcon("icon.png"), obj2, "足球");
Object[] obj2 ={ "足球", "篮球", "乒乓球" };String s = (String) JOptionPane.showInputDialog(null,"请选择你的爱好:\n", "爱好", JOptionPane.PLAIN_MESSAGE, new ImageIcon("icon.png"), obj2, "足球");
效果如下:
文本框形式的例子:
JOptionPane.showInputDialog(null,"请输入你的爱好:\n","title",JOptionPane.PLAIN_MESSAGE,icon,null,"在这输入");
JOptionPane.showInputDialog(null,"请输入你的爱好:\n","title",JOptionPane.PLAIN_MESSAGE,icon,null,"在这输入");
效果如下:
&&&&推荐文章:
【上篇】【下篇】中国Java开发网 - 怎样能够把showInputDialog里的JTextField变成JTextArea
Topic: 怎样能够把showInputDialog里的JTextField变成JTextArea
1.怎样能够把showInputDialog里的JTextField变成JTextArea
Posted by: bluepure
Posted on:
JOptionPane.showInputDialog();的输入框好像只直接支持JComboBox,JList和JTextField.有没有简单的方法(尽量少的代码)来把JTextField变成JTextArea???
2.Re:怎样能够把showInputDialog里的JTextField变成JTextArea
[Re: bluepure]
Posted by: samuel
Posted on:
JOptionPane.showInputDialog(null, new JTextArea(message), "your title")
3.Re:怎样能够把showInputDialog里的JTextField变成JTextArea
[Re: bluepure]
Posted by: bluepure
Posted on:
楼上,我早已经试过你所说的了: 代码如下: String aa="aaaa";
javax.swing.JOptionPane.showInputDialog(null, new javax.swing.JTextArea(aa), "your title") ;
System.out.println(aa);结果如下:
4.Re:怎样能够把showInputDialog里的JTextField变成JTextArea
[Re: bluepure]
Posted by: Jove
Posted on:
import&javax.swing.*;import&javax.swing.JOptionPane;public&class&TestDlg&{&&public&static&void&main(String[]&args)&{&&&&JTextArea&text&=&new&JTextArea("这家伙很懒,什么也没有留下",&3,&20);&&&&Object[]&message&=&{&"请输入100字以内的自我介绍:",&new&JScrollPane(text)};&&&&JOptionPane&pane&=&new&JOptionPane(message,&JOptionPane.INFORMATION_MESSAGE);&&&&JDialog&dialog&=&pane.createDialog(null,&"Input");&&&&dialog.show();&&&&System.out.println(text.getText());&&}}apidoc的Direct Use部分就有这种例子, 你或许没有仔细看&
5.Re:怎样能够把showInputDialog里的JTextField变成JTextArea
[Re: bluepure]
Posted by: bluepure
Posted on:
3ks Jove !!!我以后需要认真学习才是。
6.Re:怎样能够把showInputDialog里的JTextField变成JTextArea
[Re: bluepure]
Posted by: bluepure
Posted on:
JOptionPane pane = new JOptionPane(message, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);点取消的时候,无法返回null.
7.Re:怎样能够把showInputDialog里的JTextField变成JTextArea
[Re: bluepure]
Posted by: Jove
Posted on:
你是用pane.getValue()?apidoc上说可能会返回JOptionPane.UNINITIALIZED_VALUE
8.Re:怎样能够把showInputDialog里的JTextField变成JTextArea
[Re: bluepure]
Posted by: bluepure
Posted on:
我看了showInputDialog的代码了.无论点击哪个按钮,用pane.getValue()都不是想要的值.无论点击哪个按钮,text.getText()都无法得到null String
text.getText() +" "+pane.getValue()+"
"+pane.getInputValue();
9.Re:怎样能够把showInputDialog里的JTextField变成JTextArea
[Re: bluepure]
Posted by: Jove
Posted on:
hehe,那是因为jTextArea.getText()永远都不会返回null,如果没有输入,则为""
Powered by & Version Jute 1.5.6 Ent
Copyright &
Cjsdn Team. All Righits Reserved.
客服电话&&&&&客服信箱&&&&&客服QQ&714923

我要回帖

更多关于 java 空指针 的文章

 

随机推荐