import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JFrame;
public class CMain {
public static void main(String[] args) {
JFrame frame = new CMainFrame();
frame.setVisible(true);
}
}
class CMainFrame extends JFrame
{
private JPanel _ButtonPanel;
public CMainFrame(){
setTitle("小秘书");
setSize(800, 600);
setLayout(null);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
_ButtonPanel = new CButtonPanel();
_ButtonPanel.setBounds(10,10, 350, 580);
add(_ButtonPanel);
//for (int i=0 ,iLeft=10, iTop=10;iLeft<300;iLeft+=140, iTop+=145){
//}
}
}
class CButtonPanel extends JPanel
{
private JButton[] _MainButtons;
private String[] _MainButtonTitles = {"收支管理", "备忘录", "收支管理", "收支管理", "收支管理", "收支管理", "收支管理", "收支管理", "收支管理", "收支管理", "收支管理", "退出系统"};
private int iButtonWidth = 80;
private int iButtonHeight = 50;
public CButtonPanel(){
setLayout(null);
_MainButtons = new JButton[12];
//CMainButtons=new JButton[1];
//CMainButtons[0] = new JButton();
//CMainButtons[0].setLayout(null);
for (int i=0,iLeft=0,iTop=0;i<12;i++){
if (i%2==0) iLeft=0;
else iLeft=iButtonWidth*5/4;
System.out.println(_MainButtons[i]);
_MainButtons[i].setText(_MainButtonTitles[i]);
//_MainButtons[i].setBounds(iLeft, iTop+i/2*(iButtonHeight*5/4), 80, 50);
//add(_MainButtons[i]);
}
//_MainButtons[0].setBounds(0, 0, iButtonWidth, iButtonHeight);
//CMainButtons[0].setBorder(new EmptyBorder(10, 10, 10, 10));
}
}
/*class CMainButton extends JButton
{
public CMainButton(String sBtnName, int iLeft, int iTop, int iWidth, iHeight){
setTitle(sBtnName);
}
}*/
总是报标题那个错 发现只要执行跟_MainButtons[i]有关的操作就会报 可是我已经初始化了呀 为什么?