Problem in j4me Buttons

3 views
Skip to first unread message

pradeep murjwani

unread,
Sep 29, 2010, 1:28:42 AM9/29/10
to J4ME
can i add two buttons horizontally in j4me?

And 1 thing how should i select the button --->


i just added a class of Button.java and below is the code


Button b = new Button("Click here");
append(b);



Button.java file=========>

package org.j4me.ui.components;

import javax.microedition.lcdui.Graphics;

import org.j4me.ui.DeviceScreen;
import org.j4me.ui.Theme;



public class Button extends Label {
private Runnable _action; // the action on button press

public Button(String label) {
super(label);
}

public boolean acceptsInput() {
return _action != null;
}



public void keyPressed(int keyCode) {
if (keyCode == DeviceScreen.FIRE && _action != null)
_action.run();
System.out.println("clicked===");
}

public void pointerPressed(int x, int y) {
if (_action != null)
_action.run();
}

void setAction(Runnable action) {
_action = action;
System.out.println("clicked=12121==");
}


protected void paintComponent ( Graphics g , Theme theme , int
width ,int height ,boolean selected )
{
int offset = paintRect( g, theme, getX( ), 0, width,
height + 2,selected );
offset += 1;

int left = offset;
int top = offset;

height -= offset;
width -= 2 * offset;

int primaryColor = Theme.WHITE;
int secondaryColor = theme.getHighlightColor( );

// how far down the fill will peak
//
double maxSecondary = 1;

Theme.gradientFill( g, left, top, width, height,
true,primaryColor,secondaryColor, maxSecondary );
super.paintComponent( g, theme, width, height,
selected );
}
}
Reply all
Reply to author
Forward
0 new messages