2011-07-13 5 views
0

私は自分のフォームを持っていますこのフォームにようこそ私は2つのラジオボタンを持っています - 検証と登録とOKボタン。ユーザーがラジオボタンを選択してOKを押すとフォームが表示されますそれをすることはできません。助けてください。lwuitのラジオボタンコードの書き方

これは私のステートマシンのクラスコードです:あなたはGUIビルダからNetBeansプロジェクトを生成すると

package userclasses; 

import generated.StateMachineBase; 
import com.sun.lwuit.*; 
import com.sun.lwuit.events.*; 
import com.sun.lwuit.RadioButton; 
import com.sun.lwuit.Form; 
import com.sun.lwuit.util.Resources; 

public class StateMachine extends StateMachineBase implements ActionListener { 

    Resources resources; 
    RadioButton Verification = new RadioButton("Verification"); 
    RadioButton Enrollment = new RadioButton("Enrollment"); 
    StateMachineBase cl = new StateMachineBase() { }; 

    com.sun.lwuit.ButtonGroup bg=new ButtonGroup(); 

    Form fo, f; 

    public StateMachine(String resFile) { 
     super(resFile); 
     // do not modify, write code in initVars and initialize class members there, 
     // the constructor might be invoked too late due to race conditions that might occur 
    } 

    /** 
    * this method should be used to initialize variables instead of 
    * the constructor/class scope to avoid race conditions 
    */ 
    StateMachine() 
    { 
     try { 
      resources = Resources.open("/NEW AADHAR.res"); 
     } 
     catch(java.io.IOException err) { 
      err.printStackTrace(); 
     } 
     cl.setHomeForm("Welcome"); 
     fo = (Form)cl.startApp(resources,null,true); 
     f = cl.findWelcome(fo); 
     //fo.addCommandListener(this); 

     Verification = cl.findRadioButton1(f); 
     Enrollment = cl.findRadioButton(f); 
     f.addComponent(Verification); 
     f.addComponent(Enrollment); 
     //fo.addComponent(bg,null); 
     bg.add(Enrollment); 
     bg.add(Verification); 
     Verification.addActionListener(this); 
     Enrollment.addActionListener(this); 
    } 

    protected void initVars() { } 

    protected void onWelcome_OKAction(Component c, ActionEvent event) { } 

    public void actionPerformed(ActionEvent ae) { 
     throw new UnsupportedOperationException("Not supported yet."); 
    } 

    protected boolean onWelcomeEXIT() { 
     // If the resource file changes the names of components this call will break notifying you that you should fix the code 
     boolean val = super.onWelcomeEXIT(); 
     return val; 
    } 

    protected void onWelcome_ButtonAction(Component c, ActionEvent event) { 
     // If the resource file changes the names of components this call will break notifying you that you should fix the code 

     super.onWelcome_RadioButton1Action(c, event); 
     super.onWelcome_RadioButtonAction(c, event); 

     if(Verification.hasFocus()) { 
      showForm("Login",null); 
     } 
     else if(Enrollment.hasFocus()) { 
      showForm("Authentication",null); 
     } 
     else { 
      Dialog.show("INFORMATION","Please select option","OK","CANCEL"); 
     } 
    } 
| 

答えて

3

はsrcフォルダが今RESはあなたがで作業する必要があるファイルが含まれます。 GUIコードを変更するたびにStateMachineBaseが再生成されるので、GUIビルダーのコンポーネントの名前を変更できるだけです(ツリーノードをクリックしてF2キーを押すか、プロパティテーブルでname属性を選択してください)。 プロパティテーブルでは、StateMachineクラスで適切なコールバックメソッドを生成する(StateMachineクラスでのみコードを記述する)、それをサポートするすべてのコンポーネント(ラジオボタンアクションイベントなど)にイベントを割り当てることができます。

ラジオボタンは、同じグループ名を付けることで、1つのグループに関連付けることができます。

0

最も簡単な方法は、リソースエディタを使用することです。単にLWUIT/utilディレクトリから実行してください。

このツールを使用してプロジェクトを作成するには、このビデオの各手順に従います。http://www.youtube.com/watch?v=HOfb8qiySd8。必ず最後まで見てください。

4つのNetbeansプロジェクト(ProjectName、ProjectName_Desktop、ProjectName_MIDP、ProjectName_RIM)が作成されます。 depedenciesを修正し(ProjectNameと_MIDPにとって最も重要)、コーディングを開始できます。

ファイルStateMachineBase.javaは 'generated'パッケージに配置されます。つまり、リソースエディタで何かを変更するたびに再生成されます。

StateMachineクラス( 'userclasses'パッケージ)のすべてを実装しますが、そこに新しいメソッドを作成しないでください。リソースエディタを使用してリソースエディタを使用して作成します:リソースエディタ - > GUIビルダー(左側のタブ) - >イベント(右側のタブ)。

さて、あなたは例えば何かをしたい場合は、テキストフィールド値を変更したい、あなたはこのような何か書きます:

protected boolean onUstawieniaKontoZapisz() { 
// If the resource file changes the names of components this call will break notifying you that you should fix the code //this comment was generated 
boolean val = super.onUstawieniaKontoZapisz(); //generated 

Form current = Display.getInstance().getCurrent(); 

TextField login = findUstawieniaKontoLoginTextField(current); //TextField name in Editor is: 'UstawieniaKontoLoginTextField' - a bit long I know, but it's unique 
TextField password = findUstawieniaKontoHasloTextField(current); //same here, 'UstawieniaKontoHasloTextField' is second's TextField name 

Configuration.setEmail(login.getText()); //Configuration class is used to store preferences 
Configuration.setPassword(password.getText()); 

return val; //generated 
} 

をすべて見つけることができますStateMachineBaseクラス内のメソッド「*を見つけます」。リソースエディタ(GUIビルダータブ)を使用して追加した各コンポーネントごとに1つあります。

ラジオボタンをグループにグループ化するには、リソースエディタも使用し、各ラジオボタンを選択し、[プロパティ]タブの[グループ]プロパティを検索します。同じグループに入れるすべてのラジオボタンの同じ単語に設定します。