Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java GUI 设计 » Swing  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 求助:java.lang.NullPointerException问题
cxc3980





发贴: 14
积分: 0
于 2006-05-11 19:35 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
程序如下:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.util.LinkedList;
import java.text.NumberFormat;
public class Calculate extends JFrame implements ActionListener {
NumberButton numberButton[];
OperationButton operationButton[];
JButton dotButton,deButton,signButton,recButton,equalsignButton,resetButton;
JPanel panel;
JTextField resultShow;
JLabel label;
String operation[]={"+","-","*","/"};
LinkedList linkedList;
boolean PequalsignButton=false;

/** Creates a new instance of Calculate */
public Calculate() {
linkedList=new LinkedList();
numberButton=new NumberButton[10];
for(int i=0;i<=9;i++){
numberButton[i]=new NumberButtonLight Bulb;
numberButton[i].addActionListener(this);
}
operationButton=new OperationButton[4];
for(int i=0;i<3;i++){
operationButton[i]=new OperationButton(operation[i]);
operationButton[i].addActionListener(this);
}
dotButton=new JButton(".");
deButton=new JButton("de");
signButton=new JButton("+/-");
recButton=new JButton("1/x");
equalsignButton=new JButton("=");
resetButton=new JButton("reset");
dotButton.setForeground(Color.blue);
deButton.setForeground(Color.blue);
signButton.setForeground(Color.blue);
recButton.setForeground(Color.blue);
equalsignButton.setForeground(Color.blue);
resetButton.setForeground(Color.blue);
dotButton.addActionListener(this);
deButton.addActionListener(this);
signButton.addActionListener(this);
recButton.addActionListener(this);
equalsignButton.addActionListener(this);
resetButton.addActionListener(this);
resultShow=new JTextField(10);
resultShow.setHorizontalAlignment(JTextField.RIGHT);
resultShow.setForeground(Color.blue);
resultShow.setFont(new Font("TimesRoman",Font.PLAIN,14));
resultShow.setBorder(new SoftBevelBorder(BevelBorder.LOWERED));
resultShow.setBackground(Color.white);
resultShow.setEditable(false);

panel=new JPanel();
panel.setLayout(new GridLayout(4,5));

panel.add(numberButton[1]);
panel.add(numberButton[2]);
panel.add(numberButton[3]);
panel.add(operationButton[0]);
panel.add(resetButton);

panel.add(numberButton[4]);
panel.add(numberButton[5]);
panel.add(numberButton[6]);
panel.add(operationButton[1]);
panel.add(deButton);

panel.add(numberButton[7]);
panel.add(numberButton[8]);
panel.add(numberButton[9]);
panel.add(operationButton[2]);
panel.add(recButton);

panel.add(numberButton[0]);
panel.add(signButton);
panel.add(dotButton);
panel.add(operationButton[3]);
panel.add(equalsignButton);

add(panel,BorderLayout.CENTER);
add(resultShow,BorderLayout.NORTH);

addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
setVisible(true);
setBounds(100,50,240,180);
setResizable(false);
validate();
}

public void actionPerformed(ActionEvent actionEvent) {
}
public static void main(String args[]){
new Calculate();
}
}
运行后提示如下的错误:
java.lang.NullPointerException

at java.awt.Container.addImpl(Container.java:625)

at java.awt.Container.add(Container.java:307)

at Calculate.<init>(Calculate.java:96)

at Calculate.main(Calculate.java:117)

Exception in thread "main"

Java Result: 1
请问是什么原因阿?




一个程序员的奋斗历程

话题树型展开
人气 标题 作者 字数 发贴时间
7914 求助:java.lang.NullPointerException问题 cxc3980 4079 2006-05-11 19:35
6975 Re:求助:java.lang.NullPointerException问题 liuzhenke15 74 2006-05-12 13:43

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923