lol
unread,Oct 21, 2010, 12:43:09 PM10/21/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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]