| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 417 人关注过本帖
标题:运行时出现异常
取消只看楼主 加入收藏
skylyz
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-10-29
收藏
 问题点数:0 回复次数:0 
运行时出现异常

import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Calculator
{public static void main(String[] args)
{CalculatorFrame frame=new CalculatorFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}

class CalculatorFrame extends JFrame
{public static final int WIDTH=300;
public static final int HEIGHT=300;
public CalculatorFrame()
{setTitle("学生成绩管理系统");
setSize(WIDTH,HEIGHT);
Container contentPane=getContentPane();
CalculatorPanel panel=new CalculatorPanel();
contentPane.add(panel);
}
}

class CalculatorPanel extends JPanel
{private JTextField text1;
private JTextField text2;
private JTextField text3;
private JTextField text4;
private JTextField text5;
private JTextField text6;
private JButton button1;
private JButton button2;
private JButton button3;
private JButton button4;
private JLabel label1;
private JLabel label2;
private JLabel label3;
private JLabel label4;
private JLabel label5;
private JLabel label6;
private JPanel panel;
public CalculatorPanel()
{setLayout(new BorderLayout());
text1=new JTextField();
text2=new JTextField();
text3=new JTextField();
text4=new JTextField();
text5=new JTextField();
text6=new JTextField();
button1=new JButton("存储");
button1=new JButton("删除");
button1=new JButton("查询");
button1=new JButton("排序");
label1=new JLabel("学号:");
label2=new JLabel("年龄:");
label3=new JLabel("名字:");
label4=new JLabel("数学成绩:");
label5=new JLabel("英语成绩:");
label6=new JLabel("数据结构成绩:");
JPanel panel=new JPanel(new GridLayout(8,6));
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(label3);
panel.add(text3);
panel.add(label4);
panel.add(text4);
panel.add(label5);
panel.add(text5);
panel.add(label6);
panel.add(text6);
panel.add(button1);
panel.add(button2);
panel.add(button3);
panel.add(button4);
add(panel,BorderLayout.CENTER);
}

}


错误如下
---------- java ----------
Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1019)
at java.awt.Container.add(Container.java:351)
at CalculatorPanel.<init>(Calculator.java:76)
at CalculatorFrame.<init>(Calculator.java:21)
at Calculator.main(Calculator.java:8)

输出完成 (耗时: 1 秒) - 正常终止

那位帮帮忙
谢谢了

2006-11-14 20:55
快速回复:运行时出现异常
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022358 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved