当前位置: 技术问答>java相关
请您运行这个程序,为什莫会NullPointException,谢谢
来源: 互联网 发布时间:2015-02-25
本文导语: 请您运行这个程序,为什莫会NullPointException,谢谢 import java.awt.*; import java.awt.event.*; public class NumberFormatTest extends Frame implements ActionListener{ private TextField tf; private Button btn; private List list1; public static void main...
请您运行这个程序,为什莫会NullPointException,谢谢
import java.awt.*;
import java.awt.event.*;
public class NumberFormatTest extends Frame implements ActionListener{
private TextField tf;
private Button btn;
private List list1;
public static void main(String args[]){
NumberFormatTest test=new NumberFormatTest();
test.setSize(300,200);
test.setVisible(true);
}
public NumberFormatTest(){
Panel panel=new Panel();
tf=new TextField(5);
btn=new Button("OK");
btn.addActionListener(this);
List list1=new List();
//list1.add("abcdej");
panel.add(new Label("please input a number:"));
panel.add(tf);
add(panel,BorderLayout.NORTH);
add(btn,BorderLayout.SOUTH);
add(list1,BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent e){
int num;
try{
//List list1=new List(5);
list1.add("abced");
//num=Integer.parseInt(tf.getText());
//String str;
//str=Integer.toString(num);
//list1.add(str);
//list1.removeAll();
//for (int i=1;i
import java.awt.*;
import java.awt.event.*;
public class NumberFormatTest extends Frame implements ActionListener{
private TextField tf;
private Button btn;
private List list1;
public static void main(String args[]){
NumberFormatTest test=new NumberFormatTest();
test.setSize(300,200);
test.setVisible(true);
}
public NumberFormatTest(){
Panel panel=new Panel();
tf=new TextField(5);
btn=new Button("OK");
btn.addActionListener(this);
List list1=new List();
//list1.add("abcdej");
panel.add(new Label("please input a number:"));
panel.add(tf);
add(panel,BorderLayout.NORTH);
add(btn,BorderLayout.SOUTH);
add(list1,BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent e){
int num;
try{
//List list1=new List(5);
list1.add("abced");
//num=Integer.parseInt(tf.getText());
//String str;
//str=Integer.toString(num);
//list1.add(str);
//list1.removeAll();
//for (int i=1;i