刚学窗口界面设计,写了一个抽签的小程序,但是运行起来有问题,求大神帮忙诊断下
代码如下:
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.*;
public class EX3jiemian extends JFrame implements ActionListener{
private JLabel jprint1,jprint2,jprint3;
private JTextField input1,input2,input3;
private JButton button1,button2;
public EX3jiemian(){
this.setLayout(new FlowLayout ());
jprint1=new JLabel("参与抽签人数");
jprint2=new JLabel("从几号抽取");
jprint3=new JLabel("抽取人数");
input1=new JTextField(5);
input2=new JTextField(5);
input3=new JTextField(5);
button1=new JButton("确定");
button2=new JButton("重置");
this.add(jprint1);
this.add(input1);
this.add(jprint2);
this.add(input2);
this.add(jprint3);
this.add(input3);
this.add(button1);
this.add(button2);
button1.addActionListener(this);
button2.addActionListener(this);
this.setSize(200,300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent e) {
int i=0;
JFrame j=new JFrame();
JTextArea jput=new JTextArea();
j.add(jput);
j.setSize(200, 200);
if(e.getSource()==button1){
Vector vector=new Vector(3,3);
int a=Integer.getInteger(input1.getText()); //用getText拿到input1里面的内容
int b=Integer.getInteger(input2.getText());
int c=Integer.getInteger(input3.getText());
j.setVisible(true);
for(i=0;i<c;i++){
int n=(int)(Math.random()*(b+1)+a-b);
vector.add(n);
for(int k=0;k<i;k++){ //这个地方为什么会死循环?
if(vector.get(i)==vector.get(k)){
--i;
break;
}
}
}
for(i=0;i<c;i++){
jput.setText((String) vector.get(i));
}
}
if(e.getSource()==button2){
input1.setText("");
input2.setText("");
input3.setText("");
jput.setText("");
}
}
public static void main(String[] args){
new EX3jiemian();
}
}
异常:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at shangji9.EX3jiemian.actionPerformed(EX3jiemian.java:58)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:729)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.awt.EventQueue$3.run(EventQueue.java:686)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:702)
at java.awt.EventQueue$4.run(EventQueue.java:700)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:699)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
抛出这么多异常。。。。。。。。
请问是需要怎么修改。。哪里出错了。貌似不只一处错误