4
私はLWUITパッケージで簡単なJ2MEプログラムを書いています。私はMIDLETクラスファイルにForm
を追加しました。ユーザーがキーを押してからForm
を表示したいとしますが、LWUIT Form
でキーイベントを取得できませんでした。LWUIT形式のキー押下イベントを検出する方法は?
これは、あなたがForm.addGameKeyListener(here the key, here actionListener)
キーは、例えばCanvas.FIRE
ようCanvas
を使用してマッピングされて使用する必要がLWUIT Form
でイベントキーをキャプチャする
import javax.microedition.midlet.*;
import com.sun.lwuit.*;
import com.sun.lwuit.events.*;
public class MultipleForm extends MIDlet implements ActionListener{
private Form mFirstForm, mSecondForm;
public void startApp()
{
if (mFirstForm == null)
{
Display.init(this);
mFirstForm = new Form("First Form");
Button button = new Button("Switch");
button.addActionListener(this);
mFirstForm.addComponent(button);
mSecondForm = new Form("Second Form");
Button button2 = new Button("Switch");
button2.addActionListener(this);
mSecondForm.addComponent(button2);
mFirstForm.show();
}
}
protected void keyPressed(int key)
{
System.out.println("Key Pressed");
if(key==52)
{
Form current = Display.getInstance().getCurrent();
if (current == mFirstForm)
{
mSecondForm.show();
}
else if(current==mSecondForm)
{
mFirstForm.show();
}
}
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
}
私たちが右クリックしたすべてのキーにゲームのキーリスナーを追加する必要があります。LCDUIでは、keyPressed(int key)をオーバーライドして、そのキーのコードをチェックして、それで、LCDUIのようにLWUITに汎用的な仕組みがありますか? – Saravanan
フォームのkeyPressed/releaseをオーバーライドして、同じ効果を得ることができます。 keyReleasedを使用することをお勧めします。 –
この提案の理由は何ですか? –