質問内容
質問を評価する
(0ポイント)
|
このようなプログラムを書いたのですが nullpointerexceptionのエラーが出てしまいます。何故 でしょうか? プログラムはとりあえず一番最初のメニュー画面を出そ うとしているものです。
//import文を用いて長い名前を短く省略する import java.awt.Label; import java.applet.Applet; import java.awt.Button; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.*; import javax.swing.*; import java.util.*;
public class BankPanelApplet extends Applet implements ActionListener{ Panel menuPanel;//口座開設、口座解約、預金、払 い戻し、残高照会を選択する画面を表示する Panel openPanel;//口座開設を行うための画面を表 示する Panel closePanel;//口座解約を行うための画面を 表示する Panel depositPanel;//預金を行うために画面を表 示する Panel withdrawPanel;//引き出しを行うための画面 を表示する Panel balancePanel;//残高照会を行うための画面 を表示する Panel bankPanel;//ほかの画面を統合する役割を持 つ、ATMの主画面を表示する Button OpenButton;//口座開設ボタン Button CloseButton;//口座解約ボタン Button DepositButton;//預金ボタン Button WithdrawButton;//引き出しボタン Button BalanceButton;//残高照会ボタン Button EndButton;//終了ボタン Button CancelButton [] = new Button[5];//各キ ャンセルボタンを格納する Button OkButton [] = new Button[5];//各okボタ ンを格納する CardLayout cards;
//各オブジェクトの作成(メニュー画面) private Panel m_Grid; private Label m_topLabel; private Label m_bottomLabel;
//各オブジェクトの作成(開設画面) Label o_nameLabel,o_topLabel,o_bottomLabel;// ラベルオブジェクトの作成 TextField o_text;//テキストフィールド
//各オブジェクトの作成(解約画面) Label c_nameLabel,c_topLabel,c_bottomLabel;// ラベルオブジェクトの作成 TextField c_text;//テキストフィールド
//各オブジェクトの作成(預金画面) Label d_nameLabel,d_amountLabel,d_topLabel,d_bottomLabel ;//ラベルオブジェクトの作成 TextField d_text1,d_text2;//テキストフィールド
//各オブジェクトの作成(引き出し画面) Label w_nameLabel,w_amountLabel,w_topLabel,w_bottomLabel ;//ラベルオブジェクトの作成 TextField w_text1,w_text2;//テキストフィールド
//各オブジェクトの作成(残高画面) Label b_nameLabel,b_topLabel,b_bottomLabel;// ラベルオブジェクトの作成 TextField b_text1;//テキストフィールド
public void init(){
int i;//for文ループ制御用変数
//複数回使用するボタンの生成 for(i = 0; i < 5; i++){ CancelButton[i] = new Button("Cancel");//Cancelボタンを生成 OkButton[i] = new Button("OK");//OKボ タンを生成
//アプレットがボタンのアクションリスナ ーであることを指定する CancelButton[i].addActionListener(this); OkButton[i].addActionListener(this); }
createMenuPanel(); createOpenPanel(); createClosePanel(); createDepositPanel(); createWithdrawPanel(); createBalancePanel(); createBankPanel(); this.add(bankPanel); }
//メニュー画面 public void createMenuPanel(){ //各ラベルの作成 m_topLabel = new Label("java銀行へようこ そ"); m_bottomLabel = new Label("希望の処理を選 択してください");
//各ボタンの作成 OpenButton = new Button("口座開設"); CloseButton = new Button("口座解約"); DepositButton = new Button("預金"); WithdrawButton = new Button("払い戻し"); BalanceButton = new Button("残高照会"); EndButton = new Button("終了"); //レイアウトパネルの作成 m_Grid= new Panel(new GridLayout(3,2));
//パネルにボタンを追加 m_Grid.add(OpenButton); m_Grid.add(CloseButton); m_Grid.add(DepositButton); m_Grid.add(WithdrawButton); m_Grid.add(BalanceButton); m_Grid.add(EndButton); //アプレットがボタンのアクションリスナーで あることを指定する OpenButton.addActionListener(this); CloseButton.addActionListener(this); DepositButton.addActionListener(this); WithdrawButton.addActionListener(this); BalanceButton.addActionListener(this); EndButton.addActionListener(this); menuPanel.add(m_Grid); }
//口座開設画面 public void createOpenPanel(){
//ラベルの作成 o_nameLabel = new Label("口座開設画面"); o_topLabel = new Label("NAME"); o_bottomLabel = new Label("開設する口座名 を指定してください");
o_text = new TextField();//テキストフィー ルドの作成
openPanel.setLayout(new FlowLayout());//レ イアウトを設定
//パネルにボタン、ラベル、テキストフィール ドを追加 openPanel.add(o_topLabel); openPanel.add(o_nameLabel); openPanel.add(o_text); openPanel.add(CancelButton[0]); openPanel.add(OkButton[0]); openPanel.add(o_bottomLabel); }
//口座解約画面 public void createClosePanel(){
//ラベルの作成 c_nameLabel = new Label("口座解約画面"); c_topLabel = new Label("NAME"); c_bottomLabel = new Label("解約する口座名 を指定してください");
c_text = new TextField();//テキストフィー ルドの作成
closePanel.setLayout(new FlowLayout());// レイアウトを設定
//パネルにボタン、ラベル、テキストフィール ドを追加 closePanel.add(c_topLabel); closePanel.add(c_nameLabel); closePanel.add(c_text); closePanel.add(CancelButton[1]); closePanel.add(OkButton[1]); closePanel.add(c_bottomLabel); }
//預金画面 public void createDepositPanel(){
//ラベルの作成 d_nameLabel = new Label("預金画面"); d_topLabel = new Label("NAME"); d_amountLabel = new Label("Amount"); d_bottomLabel = new Label("預金する口座名 と金額を指定してください");
//テキストフィールドの作成 d_text1 = new TextField(); d_text2 = new TextField(); depositPanel.setLayout(new FlowLayout());//レイアウトを設定
//パネルにボタン、ラベル、テキストフィール ドを追加 depositPanel.add(d_topLabel); depositPanel.add(d_nameLabel); depositPanel.add(d_text1); depositPanel.add(d_amountLabel); depositPanel.add(d_text2); depositPanel.add(CancelButton[2]); depositPanel.add(OkButton[2]); depositPanel.add(d_bottomLabel);
}
//引き出し画面 public void createWithdrawPanel(){ Label d_nameLabel,d_amountLabel,d_topLabel,d_bottomLabel ;//ラベルオブジェクトの作成 TextField d_text1,d_text2;//テキストフィー ルド
//ラベルの作成 w_nameLabel = new Label("引き出し画面"); w_topLabel = new Label("NAME"); w_amountLabel = new Label("Amount"); w_bottomLabel = new Label("引き出しする口 座名と金額を指定してください");
//テキストフィールドの作成 w_text1 = new TextField(); w_text2 = new TextField();
withdrawPanel.setLayout(new FlowLayout());//レイアウトを設定
//パネルにボタン、ラベル、テキストフィール ドを追加 withdrawPanel.add(w_topLabel); withdrawPanel.add(w_nameLabel); withdrawPanel.add(w_text1); withdrawPanel.add(w_amountLabel); withdrawPanel.add(w_text2); withdrawPanel.add(CancelButton[3]); withdrawPanel.add(OkButton[3]); withdrawPanel.add(w_bottomLabel); }
public void createBalancePanel(){ //ラベルの作成 b_nameLabel = new Label("残高照会画面"); b_topLabel = new Label("NAME"); b_bottomLabel = new Label("残高照会する口 座名を指定してください");
b_text1 = new TextField();//テキストフィー ルドの作成
balancePanel.setLayout(new FlowLayout());//レイアウトを設定
//パネルにボタン、ラベル、テキストフィール ドを追加 balancePanel.add(b_topLabel); balancePanel.add(b_nameLabel); balancePanel.add(b_text1); balancePanel.add(CancelButton[4]); balancePanel.add(OkButton[4]); balancePanel.add(b_bottomLabel);
}
public void createBankPanel(){ cards = new CardLayout(); bankPanel.setLayout(cards); bankPanel.add("menu",menuPanel); bankPanel.add("open",openPanel); bankPanel.add("close",closePanel); bankPanel.add("deposit",depositPanel); bankPanel.add("withdraw",withdrawPanel); bankPanel.add("balance",balancePanel); }
public void actionPerformed(ActionEvent e){
}
}
|