pic + label selection

3 views
Skip to first unread message

JB

unread,
Oct 15, 2010, 5:22:10 AM10/15/10
to J4ME
Hi all,

First of all, thank you for the excellent contribution of J4ME lib. I
just wanted to know how can I be able select "pic + label "component
to take me to next screen, like the way menu componets works?

Thank you in advance.

michael...@googlemail.com

unread,
Oct 20, 2010, 9:33:53 AM10/20/10
to J4ME
Hi,

The label class doesn't contain any direct way to link to another
screen, but you can implement it with a simple bit of OO.

Simply create a new class that extents the label (etc) class and
overide the keyPressed event (inherited from the Component class):

{{code}}
public void keyPressed(int keyCode) {
if(keyCode == DeviceScreen.FIRE){
...
}
}
{{/code}}

Call the screen from within that method (or call another method /
handler).

Best regards,
Michael

lol

unread,
Oct 21, 2010, 12:43:09 PM10/21/10
to J4ME
A little bit of OO here (forgive me for other functionality):
class ImageAndString extends Component{

Graphics g;
Image imgOn;
Image imgOff;
boolean on=false;
int width=54;
String str="default";

public ImageAndString (String str){
try{
this.str=str;
this.imgOn=Image.createImage("/on.png");
this.imgOff=Image.createImage("/off.png");
Image canvas=Image.createImage(this.width,imgOn.getHeight());//
works with 1,1
g=canvas.getGraphics();
g.drawImage(imgOff,0,0,Graphics.TOP|Graphics.LEFT);
}catch(IOException e){}
}
public void setOn(boolean on,String str)
{
this.on=on;
this.str=str;
repaint();
}
public void paintComponent(Graphics g,Theme t,int w,int h, boolean
s){
//Image img;
if (on){
g.drawImage(imgOn,0,0,Graphics.TOP|Graphics.LEFT);
}else{
g.drawImage(imgOff,0,0,Graphics.TOP|Graphics.LEFT);
}
g.drawString(this.str,imgOn.getWidth()+3 ,((int)
(imgOn.getHeight()/2))-(int)(g.getFont().getHeight()/2),Graphics.TOP|
Graphics.LEFT);
//paintComponent(p,t,w,h,s);
}
public int[] getPreferredComponentSize(Theme theme, int
viewportWidth, int viewportHeight){
int[] i=new int[2];
i[0]=this.width;
i[1]=imgOn.getHeight();
return i;
}
}

Have fun :) [I am looking for a job]

JB

unread,
Oct 21, 2010, 2:51:19 AM10/21/10
to J4ME
Thank you for all your responds, but just figured it out and it works.

I implemented MenuItemX in the class that i wanted my menu link to go
to, then called WeatherScreen class onSelection() method.

i.e
public void onSelection() {
/**
* On selection go to this screen.
*/
midlet.showWeatherScreen();
}

Then I append the class on the menu.

e.g: WeatherScreen weatherView = new WeatherScreen (midlet);
menu.appendMenuOption(cc2, weatherView);

When you select this menu it will take you to WeatherScreen class.

Hope it makes, thanks.

On Oct 20, 1:33 am, "michael.ebb...@googlemail.com"
> > Thank you in advance.- Hide quoted text -
>
> - Show quoted text -

Amit S

unread,
Oct 21, 2010, 10:30:06 AM10/21/10
to J4ME
Hey JB,

I have done this before..

fireButtonPicture = new Picture() {
public boolean acceptsInput() {
return true;
}

public void keyPressed(int keyCode) {
if (keyCode > 0 || keyCode == DeviceScreen.FIRE)
showNewScreen();
}

};

hope this helps.

JB

unread,
Oct 22, 2010, 2:28:11 AM10/22/10
to J4ME
Thanks for all your solutions guys. Much appreciated!
Reply all
Reply to author
Forward
0 new messages