JOptionPane.showMessageDialog使用问题

hardy2014 2008-08-31 10:43:36
import javax.swing.JOptionPane;
import java.lang.*;

public class JOptionpaneTest {
public static void main(String args[])
{
String number,Output;
int n ;
int s=0 ;
number=JOptionPane.showInputDialog("Enter a Number:");

n=Integer.parseInt(number);

for (int i=1;i<=n;i++)
{s+=i;}

JOptionPane.showMessageDialog(null,s,JOptionPane.PLAIN_MESSAGE);
System.out.println("S="+s);

System.exit(0);
}
}

编译后的信息:
D:\Jcreator\chap2\JOptionpaneTest\JOptionpaneTest.java:25: 找不到符号符号: 方法 showMessageDialog(<nulltype>,int,int)
位置: 类 javax.swing.JOptionPane
JOptionPane.showMessageDialog(null,s,JOptionPane.PLAIN_MESSAGE);

不知道为什么说找不到符号??有劳各位帮忙了,谢谢!
...全文
3276 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xgsy2008061227 2010-03-14
  • 打赏
  • 举报
回复
是JOptionPane.showMessageDialog(null,s,JOptionPane.PLAIN_MESSAGE);这句出问题了,
s是你的结果,但是你没有返回的符号,简单说就是你的结果没有接收者,你应该在s后面加个接收对象,
其实你可以看书,仔细点,你会发现都有的是用""引起来的,比如"结果",这就是一个符号。你可以试试
hardy2014 2008-08-31
  • 打赏
  • 举报
回复
OK了,谢谢两位了!
老紫竹 2008-08-31
  • 打赏
  • 举报
回复
package net.java2000.swing;
import javax.swing.JOptionPane;
public class JOptionpaneTest {
public static void main(String args[]) {
String number, Output;
int n;
int s = 0;
number = JOptionPane.showInputDialog("Enter a Number:");
n = Integer.parseInt(number);
for (int i = 1; i <= n; i++) {
s += i;
}
JOptionPane.showMessageDialog(null, null,""+s, JOptionPane.PLAIN_MESSAGE);
System.out.println("S=" + s);
System.exit(0);
}
}
huoyin 2008-08-31
  • 打赏
  • 举报
回复
你的这个是因为参数类型不对,换成这个试试:
JOptionPane.showMessageDialog(null,String.valueOf(s),"Number",JOptionPane.PLAIN_MESSAGE);
java项目package project.action.dialogAction; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JOptionPane; import project.dao.common.DbException; import project.dao.dataDao.LoginInfoDao; import project.dao.dataDaoImpl.LoginInfoDaoImpl; import project.view.dialog.AddLoginInfoDialog; import project.vo.LoginInfoVo; /** * 添加登录账号action * * @author Administrator * */ public class AddLoginInfoAction implements ActionListener { private AddLoginInfoDialog dialog; public AddLoginInfoAction(AddLoginInfoDialog dialog) { this.dialog = dialog; } public void actionPerformed(ActionEvent e) { String name = e.getActionCommand(); if (name.equals("确定")) { // 检验输入是否正确 if (dialog.checkInputValue()) { LoginInfoDao dao = null; LoginInfoVo vo = null; try { // 获得界面输入信息 vo = dialog.getInputInfo(); String confirm = dialog.getConfirm(); if (vo.getLog_pwd().equals(confirm)) { dao = new LoginInfoDaoImpl(); if (dao.insertLoginInfo(vo)) { // 打印提示信息 JOptionPane.showMessageDialog(null, "添加登录人员成功", "提示信息", JOptionPane.YES_OPTION); dialog.dispose(); } else { // 打印提示信息 JOptionPane.showMessageDialog(null, "添加登录人员失败", "提示信息", JOptionPane.YES_OPTION); } } else { // 如果密码确认输入错误,打印提示信息 JOptionPane.showMessageDialog(null, "密码确认错误,请重新输入", "提示信息", JOptionPane.YES_OPTION); } } catch (DbException ex) { JOptionPane.showMessageDialog(null, ex.getMessage(), "提示信息", JOptionPane.YES_OPTION); } } else { JOptionPane.showMessageDialog(null, "请确认输入是否完整正确", "提示信息", JOptionPane.YES_OPTION); } } else if (name.equals("取消")) { dialog.dispose(); } } }
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Text extends JFrame implements ActionListener,TextListener { private JLabel username,password,email,telephone; private JTextField usernameField,emailField; private TextField teleField; private JPasswordField passwordField; private JButton registButton,cancelButton; public Text() { super("用户注册"); Container container = getContentPane(); container.setLayout(new FlowLayout()); username = new JLabel("用户名"); username.setToolTipText("请输入用户名"); password = new JLabel("密 码"); password.setToolTipText("密码不能少于6位"); email = new JLabel("邮 箱"); email.setToolTipText("邮箱中必须包含@字符"); telephone = new JLabel("电 话"); telephone.setToolTipText("电话只能为数字"); usernameField = new JTextField(15); usernameField.addActionListener(this); passwordField = new JPasswordField(15); passwordField.addActionListener(this); emailField = new JTextField(15); emailField.addActionListener(this); teleField = new TextField(21); teleField.addActionListener(this); teleField.addTextListener(this); registButton = new JButton("注册"); cancelButton = new JButton("取消"); container.add(username); container.add(usernameField); container.add(password); container.add(passwordField); container.add(email); container.add(emailField); container.add(telephone); container.add(teleField); container.add(registButton); container.add(cancelButton); registButton.addActionListener(this); cancelButton.addActionListener(this); setSize(250,200); setVisible(true); setResizable(false); } public void textValueChanged(TextEvent event) { if (event.getSource() == teleField) { /*if (!checkNumber(teleField.getText())) { JOptionPane.showMessageDialog(this,"电话必须为数字","温馨提示",JOptionPane.INFORMATION_MESSAGE); teleField.setText(""); } */ } } public void actionPerformed(ActionEvent event) { if (event.getSource() == usernameField) { if (usernameField.getText().equals("")) { JOptionPane.showMessageDialog(null,"用户名不能为空","温馨提示",JOptionPane.INFORMATION_MESSAGE); } } if (event.getSource() == passwordField) { if (passwordField.getPassword().length == 0) { JOptionPane.showMessageDialog(this,"密码不能为空","温馨提示",JOptionPane.INFORMATION_MESSAGE); } else if (passwordField.getPassword().length < 6) { JOptionPane.showMessageDialog(this,"密码长度不能小于6位","温馨提示",JOptionPane.INFORMATION_MESSAGE); passwordField.setText(""); } } if (event.getSource() == emailField) { if (emailField.getText().indexOf("@") < 0 || emailField.getText().indexOf("@") >= (emailField.getText().length() - 1) || emailField.getText().equals("")) { JOptionPane.showMessageDialog(this,"您的邮箱格式不正确","温馨提示",JOptionPane.INFORMATION_MESSAGE); emailField.setText(""); } } if (event.getSource() == teleField) { if (teleField.getText().equals("")) { JOptionPane.showMessageDialog(this,"联系电话不能为空","温馨提示",JOptionPane.INFORMATION_MESSAGE); } else if (!checkNumber(teleField.getText())) { JOptionPane.showMessageDialog(this,"电话必须为数字","温馨提示",JOptionPane.INFORMATION_MESSAGE); teleField.setText(""); } } if (event.getSource() == registButton) { if (usernameField.getText().equals("") || passwordField.getPassword().length == 0 || emailField.getText().equals("") || teleField.getText().equals("")) { JOptionPane.showMessageDialog(this, "您填写的信息不完整","温馨提示",JOptionPane.INFORMATION_MESSAGE); usernameField.setText(""); passwordField.setText(""); emailField.setText(""); teleField.setText(""); } else if (passwordField.getPassword().length < 6) { JOptionPane.showMessageDialog(this,"密码长度不能小于6位","温馨提示",JOptionPane.INFORMATION_MESSAGE); passwordField.setText(""); } else if (emailField.getText().indexOf("@") < 0 || emailField.getText().indexOf("@") >= (emailField.getText().length() - 1)) { JOptionPane.showMessageDialog(this,"您的邮箱格式不正确","温馨提示",JOptionPane.INFORMATION_MESSAGE); emailField.setText(""); } else if (!checkNumber(teleField.getText())) { JOptionPane.showMessageDialog(this,"电话必须为数字","温馨提示",JOptionPane.INFORMATION_MESSAGE); teleField.setText(""); } else JOptionPane.showMessageDialog(this,"恭喜您,注册成功","温馨提示",JOptionPane.INFORMATION_MESSAGE); } if (event.getSource() == cancelButton) { usernameField.setText(""); passwordField.setText(""); emailField.setText(""); teleField.setText(""); } } public boolean checkNumber(String str) { for (int i=0;i

50,535

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧