| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1292 人关注过本帖
标题:[求助]一个简单的积点计算器
只看楼主 加入收藏
syuanq
Rank: 2
等 级:新手上路
威 望:3
帖 子:297
专家分:0
注 册:2006-12-11
结帖率:0
收藏
 问题点数:0 回复次数:9 
[求助]一个简单的积点计算器

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Cdjs extends JFrame
{
JLabel lb1=new JLabel("上学期");
JLabel lb2=new JLabel("物理");
JLabel lb3=new JLabel("英语");
JLabel lb4=new JLabel("马哲");
JLabel lb5=new JLabel("平面设计");
JLabel lb6=new JLabel("阴影透视");
JLabel lb7=new JLabel("记组");
JLabel lb8=new JLabel("记组实验");
JLabel lb9=new JLabel("数图处理");
JLabel lb10=new JLabel("数图实验");
JTextField tf2=new JTextField();
JTextField tf3=new JTextField();
JTextField tf4=new JTextField();
JTextField tf5=new JTextField();
JTextField tf6=new JTextField();
JTextField tf7=new JTextField();
JTextField tf8=new JTextField();
JTextField tf9=new JTextField();
JTextField tf10=new JTextField();

JLabel lb11=new JLabel("下学期");
JLabel lb12=new JLabel("英语");
JLabel lb13=new JLabel("CG");
JLabel lb14=new JLabel("思修");
JLabel lb15=new JLabel("素描");
JLabel lb16=new JLabel("数媒技术");
JLabel lb17=new JLabel("SolidWorks");
JTextField tf12=new JTextField();
JTextField tf13=new JTextField();
JTextField tf14=new JTextField();
JTextField tf15=new JTextField();
JTextField tf16=new JTextField();
JTextField tf17=new JTextField();

JButton bt=new JButton("确定");
JLabel lb18=new JLabel("积点");
JTextField tf18=new JTextField();

public Cdjs()
{
super("简单积点计算器");
Container c=getContentPane();
c.setLayout(null);

lb1.setBounds(10,5,50,20);
lb2.setBounds(10,25,50,20);tf2.setBounds(70,25,30,20);
lb3.setBounds(110,25,50,20);tf3.setBounds(170,25,30,20);
lb4.setBounds(210,25,50,20);tf4.setBounds(270,25,30,20);

lb5.setBounds(10,50,60,20);tf5.setBounds(70,50,30,20);
lb6.setBounds(110,50,60,20);tf6.setBounds(170,50,30,20);
lb7.setBounds(210,50,50,20);tf7.setBounds(270,50,30,20);

lb8.setBounds(10,75,60,20);tf8.setBounds(70,75,30,20);
lb9.setBounds(110,75,60,20);tf9.setBounds(170,75,30,20);
lb10.setBounds(210,75,60,20);tf10.setBounds(270,75,30,20);

lb11.setBounds(10,100,50,20);
lb12.setBounds(10,125,50,20);tf12.setBounds(70,125,30,20);
lb13.setBounds(110,125,50,20);tf13.setBounds(170,125,30,20);
lb14.setBounds(210,125,50,20);tf14.setBounds(270,125,30,20);

lb15.setBounds(10,150,60,20);tf15.setBounds(70,150,30,20);
lb16.setBounds(110,150,60,20);tf16.setBounds(170,150,30,20);
lb17.setBounds(210,150,60,20);tf17.setBounds(270,150,30,20);

lb18.setBounds(10,200,60,20);tf18.setBounds(70,200,50,20);bt.setBounds(200,200,60,30);

c.add(lb1);
c.add(lb2);
c.add(lb3);
c.add(lb4);
c.add(lb5);
c.add(lb6);
c.add(lb7);
c.add(lb8);
c.add(lb9);
c.add(lb10);
c.add(lb11);
c.add(lb12);
c.add(lb13);
c.add(lb14);
c.add(lb15);
c.add(lb16);
c.add(lb17);

c.add(tf2);
c.add(tf3);
c.add(tf4);
c.add(tf5);
c.add(tf6);
c.add(tf7);
c.add(tf8);
c.add(tf9);
c.add(tf10);
c.add(tf12);
c.add(tf13);
c.add(tf14);
c.add(tf15);
c.add(tf16);
c.add(tf17);

c.add(lb18);
c.add(tf18);
c.add(bt);

setSize(320,300);
setLocation(300,200);
setVisible(true);
setResizable(false);

bt.addActionListener(new shijian());

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
class shijian implements ActionListener
{


public void actionPerformed(ActionEvent e)
{
if(e.getSource()==bt)
{
String str2=tf2.getText();double num2=Integer.parseInt(str2);
String str3=tf3.getText();double num3=Integer.parseInt(str3);
String str4=tf4.getText();double num4=Integer.parseInt(str4);
String str5=tf5.getText();double num5=Integer.parseInt(str5);
String str6=tf6.getText();double num6=Integer.parseInt(str6);
String str7=tf7.getText();double num7=Integer.parseInt(str7);
String str8=tf8.getText();double num8=Integer.parseInt(str8);
String str9=tf9.getText();double num9=Integer.parseInt(str9);
String str10=tf10.getText();double num10=Integer.parseInt(str10);
String str12=tf12.getText();double num12=Integer.parseInt(str12);
String str13=tf13.getText();double num13=Integer.parseInt(str13);
String str14=tf14.getText();double num14=Integer.parseInt(str14);
String str15=tf15.getText();double num15=Integer.parseInt(str15);
String str16=tf16.getText();double num16=Integer.parseInt(str16);
String str17=tf17.getText();double num17=Integer.parseInt(str17);
double jd;
jd=(num2-50)/10*2.0+(num3-50)/10*3.5+(num4-50)/10*2.0+(num5-50)/10*2.0+(num6-50)/10*2.5+
(num7-50)/10*3.0+(num8-50)/10*2.0+(num9-50)/10*2.0+(num10-50)/10*1.0;
String str=String.valueOf(jd);
tf18.setText(str);

}
}
}

public static void main(String args[])
{
new Cdjs();
}
}
这个程序能运行了,但是为什么输入数后点击确定时却出现错误呢?下面是抛出的异常:
--------------------Configuration: <Default>--------------------
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:468)
at java.lang.Integer.parseInt(Integer.java:497)
at Cdjs$shijian.actionPerformed(Cdjs.java:130)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

Process completed.

搜索更多相关主题的帖子: JLabel 计算器 new 英语 
2007-07-04 13:32
maoguoqing
Rank: 6Rank: 6
来 自:重庆
等 级:贵宾
威 望:28
帖 子:2980
专家分:19
注 册:2005-12-5
收藏
得分:0 
你输入的不是数的格式不正确吧

天行健,君子以自强不息!!QQ:68660681
2007-07-04 14:00
maoguoqing
Rank: 6Rank: 6
来 自:重庆
等 级:贵宾
威 望:28
帖 子:2980
专家分:19
注 册:2005-12-5
收藏
得分:0 
或者是有某一个你没有输入。。

天行健,君子以自强不息!!QQ:68660681
2007-07-04 14:00
syuanq
Rank: 2
等 级:新手上路
威 望:3
帖 子:297
专家分:0
注 册:2006-12-11
收藏
得分:0 
不是啊!每个数我都输入了啊!不过就是错误哦!请运行一下啊

[url]www.[/url]欢迎大家的光临,一起交流学习
2007-07-04 14:03
maoguoqing
Rank: 6Rank: 6
来 自:重庆
等 级:贵宾
威 望:28
帖 子:2980
专家分:19
注 册:2005-12-5
收藏
得分:0 
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
不就表示你输入了一个空串吗?或者看看你输入的数前面是否有空格?或者你全输整数看看出错与否?

天行健,君子以自强不息!!QQ:68660681
2007-07-04 14:07
syuanq
Rank: 2
等 级:新手上路
威 望:3
帖 子:297
专家分:0
注 册:2006-12-11
收藏
得分:0 

我输入的就是全部都是整数哦,前面也没有空格,可是还是出错,忧闷


[url]www.[/url]欢迎大家的光临,一起交流学习
2007-07-04 14:53
大嘴先生2
Rank: 1
等 级:新手上路
威 望:2
帖 子:815
专家分:0
注 册:2006-4-17
收藏
得分:0 
mport java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Moon extends JFrame
{
JLabel lb1=new JLabel("上学期");
JLabel lb2=new JLabel("物理");
JLabel lb3=new JLabel("英语");
JLabel lb4=new JLabel("马哲");
JLabel lb5=new JLabel("平面设计");
JLabel lb6=new JLabel("阴影透视");
JLabel lb7=new JLabel("记组");
JLabel lb8=new JLabel("记组实验");
JLabel lb9=new JLabel("数图处理");
JLabel lb10=new JLabel("数图实验");
JTextField tf2=new JTextField();
JTextField tf3=new JTextField();
JTextField tf4=new JTextField();
JTextField tf5=new JTextField();
JTextField tf6=new JTextField();
JTextField tf7=new JTextField();
JTextField tf8=new JTextField();
JTextField tf9=new JTextField();
JTextField tf10=new JTextField();

JLabel lb11=new JLabel("下学期");
JLabel lb12=new JLabel("英语");
JLabel lb13=new JLabel("CG");
JLabel lb14=new JLabel("思修");
JLabel lb15=new JLabel("素描");
JLabel lb16=new JLabel("数媒技术");
JLabel lb17=new JLabel("SolidWorks");
JTextField tf12=new JTextField();
JTextField tf13=new JTextField();
JTextField tf14=new JTextField();
JTextField tf15=new JTextField();
JTextField tf16=new JTextField();
JTextField tf17=new JTextField();

JButton bt=new JButton("确定");
JLabel lb18=new JLabel("积点");
JTextField tf18=new JTextField();

public Moon()
{
super("简单积点计算器");
Container c=getContentPane();
c.setLayout(null);

lb1.setBounds(10,5,50,20);
lb2.setBounds(10,25,50,20);tf2.setBounds(70,25,30,20);
lb3.setBounds(110,25,50,20);tf3.setBounds(170,25,30,20);
lb4.setBounds(210,25,50,20);tf4.setBounds(270,25,30,20);

lb5.setBounds(10,50,60,20);tf5.setBounds(70,50,30,20);
lb6.setBounds(110,50,60,20);tf6.setBounds(170,50,30,20);
lb7.setBounds(210,50,50,20);tf7.setBounds(270,50,30,20);

lb8.setBounds(10,75,60,20);tf8.setBounds(70,75,30,20);
lb9.setBounds(110,75,60,20);tf9.setBounds(170,75,30,20);
lb10.setBounds(210,75,60,20);tf10.setBounds(270,75,30,20);

lb11.setBounds(10,100,50,20);
lb12.setBounds(10,125,50,20);tf12.setBounds(70,125,30,20);
lb13.setBounds(110,125,50,20);tf13.setBounds(170,125,30,20);
lb14.setBounds(210,125,50,20);tf14.setBounds(270,125,30,20);

lb15.setBounds(10,150,60,20);tf15.setBounds(70,150,30,20);
lb16.setBounds(110,150,60,20);tf16.setBounds(170,150,30,20);
lb17.setBounds(210,150,60,20);tf17.setBounds(270,150,30,20);

lb18.setBounds(10,200,60,20);tf18.setBounds(70,200,50,20);bt.setBounds(200,200,60,30);

c.add(lb1);
c.add(lb2);
c.add(lb3);
c.add(lb4);
c.add(lb5);
c.add(lb6);
c.add(lb7);
c.add(lb8);
c.add(lb9);
c.add(lb10);
c.add(lb11);
c.add(lb12);
c.add(lb13);
c.add(lb14);
c.add(lb15);
c.add(lb16);
c.add(lb17);

c.add(tf2);
c.add(tf3);
c.add(tf4);
c.add(tf5);
c.add(tf6);
c.add(tf7);
c.add(tf8);
c.add(tf9);
c.add(tf10);
c.add(tf12);
c.add(tf13);
c.add(tf14);
c.add(tf15);
c.add(tf16);
c.add(tf17);

c.add(lb18);
c.add(tf18);
c.add(bt);

setSize(320,300);
setLocation(300,200);
setVisible(true);
setResizable(false);

bt.addActionListener(new shijian());

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
class shijian implements ActionListener
{


public void actionPerformed(ActionEvent e)
{
if(e.getSource()==bt)
{
String str2=tf2.getText();double num2=Integer.parseInt(str2);
String str3=tf3.getText();double num3=Integer.parseInt(str3);
String str4=tf4.getText();double num4=Integer.parseInt(str4);
String str5=tf5.getText();double num5=Integer.parseInt(str5);
String str6=tf6.getText();double num6=Integer.parseInt(str6);
String str7=tf7.getText();double num7=Integer.parseInt(str7);
String str8=tf8.getText();double num8=Integer.parseInt(str8);
String str9=tf9.getText();double num9=Integer.parseInt(str9);
String str10=tf10.getText();double num10=Integer.parseInt(str10);
/*String str12=tf12.getText();double num12=Integer.parseInt(str12);
String str13=tf13.getText();double num13=Integer.parseInt(str13);
String str14=tf14.getText();double num14=Integer.parseInt(str14);
String str15=tf15.getText();double num15=Integer.parseInt(str15);
String str16=tf16.getText();double num16=Integer.parseInt(str16);
String str17=tf17.getText();double num17=Integer.parseInt(str17);*/ //这段代码都没用上!
//什么问题自己再看看!
double jd;
jd=(num2-50)/10*2.0+(num3-50)/10*3.5+(num4-50)/10*2.0+(num5-50)/10*2.0+(num6-50)/10*2.5+
(num7-50)/10*3.0+(num8-50)/10*2.0+(num9-50)/10*2.0+(num10-50)/10*1.0;
String str=String.valueOf(jd);
tf18.setText(str);

}
}
}

public static void main(String args[])
{
new Moon();
}
}

骑白马的未必是王子,也可能是唐僧;有翅膀的未必是天使,也可能是鸟人。
2007-07-04 15:13
syuanq
Rank: 2
等 级:新手上路
威 望:3
帖 子:297
专家分:0
注 册:2006-12-11
收藏
得分:0 
我明白是什么问题了,原来是这段代码的问题:
String str12=tf12.getText();double num12=Integer.parseInt(str12);
String str13=tf13.getText();double num13=Integer.parseInt(str13);
String str14=tf14.getText();double num14=Integer.parseInt(str14);
String str15=tf15.getText();double num15=Integer.parseInt(str15);
String str16=tf16.getText();double num16=Integer.parseInt(str16);
String str17=tf17.getText();double num17=Integer.parseInt(str17);
这段代码我是没有用到的,所以用getText()取出的是空,会抛出异常

[url]www.[/url]欢迎大家的光临,一起交流学习
2007-07-04 15:29
xuxianyue123
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2007-6-9
收藏
得分:0 
哈哈,楼主的确输入空格,我全输入数字没错的。。
2007-07-04 15:42
syuanq
Rank: 2
等 级:新手上路
威 望:3
帖 子:297
专家分:0
注 册:2006-12-11
收藏
得分:0 

呵呵。。。楼上说的也没有错!


[url]www.[/url]欢迎大家的光临,一起交流学习
2007-07-04 21:57
快速回复:[求助]一个简单的积点计算器
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025466 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved