开发者

Set background image / color in midlet

开发者 https://www.devze.com 2023-03-15 16:23 出处:网络
I create one application used form class now its very simple,I want set background开发者_开发问答 image or color.I searched over 2 days but no use if any know share to me...Use LWUIT , create a class

I create one application used form class now its very simple,I want set background开发者_开发问答 image or color.I searched over 2 days but no use if any know share to me...


Use LWUIT , create a class which derives from Form and in its constructor call setBgImage. To create the Image object parameter of the setBgImage method use the static methods of the Image class. To download LWUIT go to http://www.oracle.com/technetwork/java/javame/javamobile/download/lwuit/index.html


Not really, if you are using Form-based UI, you are stuck with how the platform wishes to render your UI. If you need a higher level of control over the UI then you need to roll your own from scratch using Canvas.


You can't able to set the BGImage or BGColor for high level UI. If you want to do you can use Canvas or you can use some 3rd party GUI frameworks. I preferred LWUIT is the best GUI framework. You can do everything with LWUIT for j2me applications.


set the background using the method

in paint methode 
g.setColor(0xD7DFE4);

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;

public class SetColorGraphicsMIDlet extends MIDlet {
  private Display display;
  protected void startApp() {
    Canvas canvas = new LineCanvas();
    display = Display.getDisplay(this);
    display.setCurrent(canvas);
  }
  protected void pauseApp() {
  }
  protected void destroyApp(boolean unconditional) {
  }
}

class LineCanvas extends Canvas {
  public void paint(Graphics g) {
    int width = getWidth();
    int height = getHeight();
    g.setColor(0xFFFF00);
    g.drawLine(0, height / 4, width - 1, height / 4);
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消