这个java对话框程序从JOptionPane那一行到choice那一行报错怎么回事
这个java对话框程序从JOptionPane那一行到choice那一行报错怎么回事importjavax.swing.*;publicclass对话框案例{public...
这个java对话框程序从JOptionPane那一行到choice那一行报错怎么回事import javax .swing.*;
public class 对话框案例 {
public static void main(String[] args) {// TODO Auto-generated method stub
int answer = JOptionPane.showConfirmDialog(null,
"你确实需要退出本系统吗?",
"系统退出提示",
JOptionPane.YES_NO_OPTION);
if(answer == JOptionPane.YES_OPTION){}
Object[] option = {"确定","取消"};
answer = JOptionPane.showOptionDialog(null,"你确实需要退出本系统吗?",
"系统退出提示",JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
option,
option[1]);
if(answer == JOptionPane.YES_OPTION){
JOptionPane.showMessageDialog(null,"学生信息管理系统v1.1\n 指导老师: 张永常、谭兵、徐峰\n 作者: 软件1班第2小组\n 完成日期: 2012-11-8");
Object[] choices = {"关闭计算机","重新启动","注销","切换用户","睡眠"};
String choiceAnswer = (String)JOptionPane.showInputDialog(null,"请选择关机选项","关机选项",
JOptionPane,PLAIN_MESSAGE,
null,
choice,
choice[1]);
JOptionPane.showMessageDialog(null,"你的关机选项为:【"+choiceAnswer+"】");
}
}
} 展开
public class 对话框案例 {
public static void main(String[] args) {// TODO Auto-generated method stub
int answer = JOptionPane.showConfirmDialog(null,
"你确实需要退出本系统吗?",
"系统退出提示",
JOptionPane.YES_NO_OPTION);
if(answer == JOptionPane.YES_OPTION){}
Object[] option = {"确定","取消"};
answer = JOptionPane.showOptionDialog(null,"你确实需要退出本系统吗?",
"系统退出提示",JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
option,
option[1]);
if(answer == JOptionPane.YES_OPTION){
JOptionPane.showMessageDialog(null,"学生信息管理系统v1.1\n 指导老师: 张永常、谭兵、徐峰\n 作者: 软件1班第2小组\n 完成日期: 2012-11-8");
Object[] choices = {"关闭计算机","重新启动","注销","切换用户","睡眠"};
String choiceAnswer = (String)JOptionPane.showInputDialog(null,"请选择关机选项","关机选项",
JOptionPane,PLAIN_MESSAGE,
null,
choice,
choice[1]);
JOptionPane.showMessageDialog(null,"你的关机选项为:【"+choiceAnswer+"】");
}
}
} 展开
1个回答
展开全部
有2个错误:
第一个错误: JOptionPane,PLAIN_MESSAGE这里的逗号要修改成点
JOptionPane.PLAIN_MESSAGE
第二个错误:变量名书写错误
定义变量时Object[] choices ,变量的名字是choices,
使用变量时choice, choice[1]); 变量的名字是choice
修改办法统一变量名,建议统一修改成choices
完整的代码修改
String choiceAnswer = (String) JOptionPane.showInputDialog(null, "请选择关机选项", "关机选项",
JOptionPane.PLAIN_MESSAGE, null, choices, choices[1]);
测试
更多追问追答
追问
谢谢😊
你发的那两个图片是效果图吗?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询