java代码问题

来源:百度知道 编辑:UC知道 时间:2024/05/17 08:00:43
import javax.swing.*;

public class MyCalFr extends JFrame
{
private JPanel Main_Pal=new JPanel();
private JPanel Msg_Pal = new JPanel();
private JPanel Day_Pal= new JPanel();

private JLabel Year_Lab=new JLabel("年份:");
private JLabel Month_Lab = new JLabel("月份:");
private JLabel Day_Lab =new JLabel("日期:");

private JComboBox Year_Box = new JComboBox();
private JComboBox Month_Box = new JComboBox();
private JComboBox Day_Box = new JComboBox();

private JButton[] Week_button = {new JButton("日"),new JButton("一"),new JButton("二"),
new JButton("三"),new JButton("四"),new JButton("五"),
new JButton("六")};
private JButton[] Day_Button = new JButton[35];

//构造器
public MyCalFr (String str)
{
this.setTitle(str);
this.setLocation(100, 100

Day_Button[i - 1] = new JButton();
Day_Button[i - 1].setText(i + "");

记得用之前先初始化一下

空指针异常!

明显的空指针啊,你用eclipse调试下看啊

package albalb;

import java.awt.BorderLayout;
import java.awt.GridLayout;

import javax.swing.*;

public class MyCalFr extends JFrame {
private JPanel Main_Pal = new JPanel();

private JPanel Msg_Pal = new JPanel();

private JPanel Day_Pal = new JPanel();

private JLabel Year_Lab = new JLabel("年份:");

private JLabel Month_Lab = new JLabel("月份:");

private JLabel Day_Lab = new JLabel("日期:");

private JComboBox Year_Box = new JComboBox();

private JComboBox Month_Box = new JComboBox();

private JComboBox Day_Box = new JComboBox();

private JButton[] Week_button = { new JButton("日"), new JButton("一"),
new JButton("二"), ne