求java高手指点,我是新手,我的程序在第一个文本框输入值以后,按了确定就出错了
以下代码:importjava.awt.*;importjava.awt.event.ActionEvent;importjava.awt.event.ActionLis...
以下代码:
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Test extends JFrame implements ActionListener{
public static Test se;
public Container pane ;
public JTextField t1;
public String h;
public static void main(String[] args){
se=new Test();
se.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
se.setSize(800,500);
se.setVisible(true);}
public Test(){
Container pane=getContentPane();
FlowLayout ft=new FlowLayout(FlowLayout.LEFT,5,10);
pane.setLayout(ft);
pane.add(new JLabel(" 变量个数: "));
TextField t1=new TextField("0",8);
pane.add(t1);
pane.add(new JLabel(" 约束条件个数:"));
pane.add(new TextField(8));
Button b=new Button("确定");
pane.add(b);
b.addActionListener(this);
pane.add(new Button("退出"));
h=t1.getText();
}
public void actionPerformed(ActionEvent e) {
String r=t1.getText();
System.out.println(r);
}
}
错误:
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90) 展开
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Test extends JFrame implements ActionListener{
public static Test se;
public Container pane ;
public JTextField t1;
public String h;
public static void main(String[] args){
se=new Test();
se.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
se.setSize(800,500);
se.setVisible(true);}
public Test(){
Container pane=getContentPane();
FlowLayout ft=new FlowLayout(FlowLayout.LEFT,5,10);
pane.setLayout(ft);
pane.add(new JLabel(" 变量个数: "));
TextField t1=new TextField("0",8);
pane.add(t1);
pane.add(new JLabel(" 约束条件个数:"));
pane.add(new TextField(8));
Button b=new Button("确定");
pane.add(b);
b.addActionListener(this);
pane.add(new Button("退出"));
h=t1.getText();
}
public void actionPerformed(ActionEvent e) {
String r=t1.getText();
System.out.println(r);
}
}
错误:
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90) 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询