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.