// ログイン用パネルで、再利用を考えたパネル
// テキストボックスで、UserID、Passwordを入力し、OKボタンを押した時、登録データと合えばsetNextFrameで指定したFrameへ進む。
// パスワードが合わない場合、Daialogを表示させる。
// パネルレイアウトにHTMLLayoutを使う。
//
import com.nttdocomo.ui.*;//IApplicationのiアプリで使う各種クラスの利用
public class LoginPanel extends Panel implements SoftKeyListener ,ComponentListener{
IApplication i_app;//呼び出し元の作品であるHelloWorldを管理する。コンストラクタで記憶
//登録データ
public String regUserID = "YUU";
protected String regPassword = "UUY";
Frame softBackFrame = null; //ソフトキー1で進むFrame nullの指定時は終了
Frame softNextFrame = null; //ソフトキー2で進むFrame
TextBox txtUserID = new TextBox("",12,1,TextBox.DISPLAY_ANY);
TextBox txtPassword = new TextBox("",12,1,TextBox.DISPLAY_PASSWORD);
Button ntnOk = new Button(" Login ");
public LoginPanel(IApplication app,String title){
i_app = app; //plicationを継承した作品objをメモ
//int back = Graphics.getColorOfRGB(192,192,192);
//setBackground(back);
setTitle(title);
HTMLLayout lm = new HTMLLayout();
this.setLayoutManager(lm); //レイアウトマネージャ変更
Label lbl;
lbl = new Label("");
add(lbl);
lm.br(); //<br>
lbl = new Label(" UserID");
add(lbl);
lm.br(); //<br>
lm.begin(HTMLLayout.CENTER);
add(txtUserID);
lm.end();
lm.br(); //<br>
lbl = new Label("");
add(lbl);
lm.br(); //<br>
lbl = new Label(" Password");
add(lbl);
lm.br(); //<br>
lm.begin(HTMLLayout.CENTER);
add(txtPassword);
lm.end();
lm.br(); //<br>
lbl = new Label("");
add(lbl);
lm.br(); //<br>
lm.begin("RIGHT");
add(ntnOk);
lm.end();
//インターフェイスに対する初期化
setSoftKeyListener(this); // SoftKeyListener
setComponentListener(this);//コンポーネントリスナを登録
}
public void setSoft1Frame(Frame frm, String lbl){
softBackFrame = frm;
setSoftLabel(Frame.SOFT_KEY_1, lbl);
}
public void setSoft2Frame(Frame frm, String lbl){
softNextFrame = frm;
setSoftLabel(Frame.SOFT_KEY_2, lbl);
}
public void setNextFrame(Frame frm){
softNextFrame = frm;
}
public void softKeyPressed(int key_id){ //SoftKeyListenerのabstracを実装
}
public void softKeyReleased(int key_id){//SoftKeyListenerのabstracを実装
if ( key_id == Frame.SOFT_KEY_1 ){
if(softBackFrame == null){
Dialog dialog = new Dialog( Dialog.DIALOG_YESNO,"どうしますか?");
dialog.setText("本当に終了しますか");
int rtn = dialog.show();
if(rtn == Dialog.BUTTON_YES) i_app.terminate();//アプリケーション終了
} else {
Display.setCurrent(softBackFrame);//移動
}
} else if (key_id == Frame.SOFT_KEY_2 ){
//次のFrameへ移動
if(softNextFrame != null){
Display.setCurrent(softNextFrame);//移動
}
}
}
public void componentAction(Component source,int type,int param){//ComponentListenerのabstracを実装
if(source == ntnOk){
String userID = txtUserID.getText();
String password = txtPassword.getText();
if(userID.equals(regUserID) && password.equals(regPassword)){
//次のFrameへ移動
if(softNextFrame != null){
Display.setCurrent(softNextFrame);//移動
} else {
System.out.println("次のFrameが登録されていません");//デバック用
}
} else {
Dialog dialog = new Dialog( Dialog.BUTTON_OK,"メッセージ");
dialog.setText("ユーザーIDまたは パスワードが合いません");
int rtn = dialog.show();
}
}
}
}