Skip to main content

key event in lwuit

10 replies [Last post]
kavitharajdurai
Offline
Joined: 2010-08-25

now i am using LWUIT 1.4.

how to implent key event in lwuit application?

that is when i pressed Right arrow key want to display image in one form. if i pressed same key again means want to display another image. please try to give sample code like this. please i need urgent.. reply as soon as possible.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kavitharajdurai
Offline
Joined: 2010-08-25

i am already constructed that form 9. i want to show that only. i am already used that form 9 in another event. also i want to display form 9 when i pressed right arrow key inside the form 10. i am used ur code also. that code also shows same null pointer exception. provide my coding here. plz try to give better solution for me.

form 9 coding following

if(evt.getSource().equals(pictureButton8))
{
form9=new Form("");
Image image14 = null;
try {
image14= EncodedImage.createImage("/image5.png");
}
catch (IOException ex)
{
}
Label pictureLabel7 = new Label(image14);
form9.addComponent(pictureLabel7);

backCommand=new Command("Back");
form9.addCommand(backCommand);
form9.setCommandListener(this);
form9.show();
}

form10 codings are here

if(evt.getSource().equals(pictureButton9))
{
form10=new Form("");

Image image15 = null;
try {
image15= EncodedImage.createImage("/image4.png");
}
catch (IOException ex)
{
}

Label pictureLabel8 = new Label(image15);
form10.addComponent(pictureLabel8);

form10.addGameKeyListener(Display.GAME_RIGHT,new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
// throw new UnsupportedOperationException("Not supported yet.");

form9.show();
}
});

backCommand=new Command("Back");
form10.addCommand(backCommand);
form10.setCommandListener(this);
form10.show();
}

here my problem is when i click right arrow key it shows null pointer exception.
plz i need solution for this. what prolem in this coding.

shankar_vn
Offline
Joined: 2009-11-03

Use the debugger option, provided with IDE to find which line is exactly causing the null pointer exception.

kavitharajdurai
Offline
Joined: 2010-08-25

i find out this fault and finished this task. thanks for ur help.

i want to ask another doubt.

hi now i am working with LWUIT 1.4 in netbeans 6.9.1 editor and sdk 3.0 simulator.

i am creating my application using LWUIT.
in my application i want to do one task.
when i click button name is mail , want to open mail composer and i want to send text or image mail to mail account from my application. its my one of the task.

how it ll implement? try to give some guidelines about this.

i searched some material all are told send email through servlet and socket connection. but i dont have any little idea about this. also i saw some basic about mailForME open source API.i think its very useful to send mail from j2me. but i dont know how it is implemented.

try to give some guide lines about this. if possible give source code for send email through j2me. now i am working in netbeans 6.9.1, and sdk 3.0 simulator. where and how to use that MailForME API.

vprise
Offline
Joined: 2003-11-07

There are lots of ways and generally you want to consider touch as well. Just use a gamekey listener or something.

kavitharajdurai
Offline
Joined: 2010-08-25

i am working in j2me LWUIT 1.4.
my actual application is one image display on screen.(I am using form to display image). when i pressed Right arrow key it want to show another form. if i pressed again it want to show other form.
i need coding for this .

I am using code like this.
form10=new Form("")
{

public void keyPressed(int key)
{
int game=Display.getInstance().getGameAction(key);
if(game == Display.GAME_RIGHT)
{

form9.show();

}

}

};

but when i pressed right soft key it doesnt show 9th form. it display null pointer exception 0.
what can i do to show the 9th form contents?
plz i need urgent reply.

how ca i rectify this problem.

thorsten_s
Offline
Joined: 2008-08-15

The right soft key is different from the right game action.

In your case thr form9 might be null (cannot tell from your short code snippet).

Other than that, you are overriding the keyPressed(int) method and do not pass the call to the superclass as in:
[code]
public void keyPressed(int key){
super.keyPressed(key);
....
[/code]
That could become a problem in complex classes like the Form.

kavitharajdurai
Offline
Joined: 2010-08-25

i cant mean ur idea.

i dont know the difference between right soft key and game_right key.

i want to use right arrow key in keyboard as well as mobile.
how can i show form 9 contents when i pressed right arrow key???
please try to give code for this as soon as possible.

my form9 contents are,

form9=new Form("");
Image image14 = null;
try {
image14= EncodedImage.createImage("/image5.png");
}
catch (IOException ex)
{
}
Label pictureLabel7 = new Label(image14);
form9.addComponent(pictureLabel7);

backCommand=new Command("Back");
form9.addCommand(backCommand);
form9.setCommandListener(this);
form9.show();

when i pressed right arrow key i want to display that image.
i used following code but it doesnt work.

form10=new Form("")
{
public void keyPressed(int key)
{

int game=Display.getInstance().getGameAction(key);
if(game==Display.GAME_RIGHT)
{

form2.show();

}
}
};

how can i rectify my problem?

kavitharajdurai
Offline
Joined: 2010-08-25

i cant mean ur idea.

i dont know the difference between right soft key and game_right key.
because i am beginner in LWUIT and J2ME.

i want to use right arrow key in keyboard as well as mobile.
Which key i want to use? right soft key or game_right key?
what is diff b/w to these keys?
how can i show form 9 contents when i pressed right arrow key???
please try to give code for this as soon as possible.

my form9 contents are,

form9=new Form("");
Image image14 = null;
try {
image14= EncodedImage.createImage("/image5.png");
}
catch (IOException ex)
{
}
Label pictureLabel7 = new Label(image14);
form9.addComponent(pictureLabel7);

backCommand=new Command("Back");
form9.addCommand(backCommand);
form9.setCommandListener(this);
form9.show();

when i pressed right arrow key i want to display that image with form.

please try to give code for to achieve my goal.

shankar_vn
Offline
Joined: 2009-11-03

[code]
form10.addGameKeyListener(Display.GAME_RIGHT, new ActionListener() {
public void actionPerformed(ActionEvent ae) {
//construct and show form9 here
}
});
[/code]

kavitharajdurai
Offline
Joined: 2010-08-25

ok. i want to show that form only. i am already construct that form.

Label pictureLabel8 = new Label(image15);
form10.addComponent(pictureLabel8);

form10.addGameKeyListener(Display.GAME_RIGHT,new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{

form9.show();
}
});

when i use this code now also it display null pointer exception.

that form 9 containing following contents.

if(evt.getSource().equals(pictureButton8))
{
form9=new Form("");
Image image14 = null;
try {
image14= EncodedImage.createImage("/image5.png");
}
catch (IOException ex)
{
}
Label pictureLabel7 = new Label(image14);
form9.addComponent(pictureLabel7);

backCommand=new Command("Back");
form9.addCommand(backCommand);
form9.setCommandListener(this);
form9.show();
}