java 网格包,一个网格包的问题

一个网格包的问题

每次做界面都会出问题。看来练习的太少了。

这次是抛出NULLpointexception。

希望,明白的人帮我看看。谢谢了~

版主提示以后改过,可是还不行。麻烦大家了,帮着看看。

下边是改过以后的代码

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

class AccountFrame extends JFrame{

Container container;

GridBagLayout gb;

GridBagConstraints gbc;

JButton ok;

JButton check;

JLabel dateLabel;

JLabel yearLabel;

JLabel monthLabel;

JLabel dayLabel;

JLabel accountLabel;

JTextField yearField;

JTextField monthField;

JTextField dayField;

JTextField accountField;

public AccountFrame(String title){

super("title");

Container container = getContentPane();

gb = new GridBagLayout();

gbc = new GridBagConstraints();

container.setLayout(gb);

ok = new JButton("存储");

check = new JButton("查询");

dateLabel = new JLabel("日期");

yearLabel = new JLabel("年");

monthLabel = new JLabel("月");

dayLabel = new JLabel("日");

yearField = new JTextField(4);

monthField = new JTextField(2);

dayField = new JTextField(2);

accountLabel = new JLabel("当日开销");

accountField = new JTextField("请输入开销");

//向容器中舔加组件

gbc.fill=GridBagConstraints.HORIZONTAL;

addComponent(dateLabel,0,0,1,1);

gbc.fill = GridBagConstraints.HORIZONTAL;

addComponent(yearField,1,0,1,1);

gbc.fill = GridBagConstraints.HORIZONTAL;

addComponent(yearLabel,1,1,1,1);

gbc.fill = GridBagConstraints.HORIZONTAL;

addComponent(monthField,1,2,1,1);

gbc.fill = GridBagConstraints.HORIZONTAL;

addComponent(monthLabel,1,3,1,1);

gbc.fill = GridBagConstraints.HORIZONTAL;

addComponent(dayField,1,4,1,1);

gbc.fill = GridBagConstraints.HORIZONTAL;

addComponent(dayLabel,1,5,1,1);

gbc.fill = GridBagConstraints.HORIZONTAL;

addComponent(accountLabel,2,0,1,1);

gbc.fill = GridBagConstraints.HORIZONTAL;

addComponent(accountField,2,1,1,1);

gbc.fill = GridBagConstraints.HORIZONTAL;

addComponent(ok,2,5,1,1);

gbc.fill = GridBagConstraints.HORIZONTAL;

addComponent(check,2,6,1,1);

}

public void addComponent(Component c,int row,int col,int nrow,int ncol) {

gbc.gridx = col;

gbc.gridy = row;

gbc.gridwidth = ncol;

gbc.gridheight = nrow;

gb.setConstraints(c,gbc);

container.add(c);

}

public static void main(String[] args){

AccountFrame mainframe = new AccountFrame("记帐");

mainframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

mainframe.setSize(400,400);

mainframe.setVisible(true);

}

}

[此贴子已经被作者于2006-5-26 3:36:08编辑过]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值