Hi. I'm trying to create a simple application that draws some things on the screen. If I do the drawing inside the paint(Graphics graphics) method everything works fine, but if I try to do it in another method outside paint it won't work at all, the screen is left white. Here is the code:
Code:
public class blackberryApp extends UiApplication {
public static void main(String[] args) {
blackberryApp theApp = new blackberryApp();
theApp.enterEventDispatcher();
}
public blackberryApp() {
//display a new screen
GameScreen Game = new GameScreen();
Game.start();
pushScreen(Game);
}
}
public class GameScreen extends FullScreen implements Runnable {
public Graphics theGraphics;
public GameScreen() {
super();
}
public void start() {
theGraphics = getGraphics();
mainThread = new Thread(this);
mainThread.start();
}
public void paint(Graphics graphics) {
}
public void draw() {
if (theGraphics != null) {
theGraphics.pushRegion(new XYRect(0, 0, 240, 260));
theGraphics.setColor(Graphics.BLACK);
theGraphics.setColor(0x00FF00);
theGraphics.fillRect(50, 50, 30, 30);
theGraphics.setColor(Graphics.WHITE);
theGraphics.drawText("It works", 20, 20);
theGraphics.popContext();
}
}
public final void run() {
while (true) {
draw();
invalidate();
try {
Thread.sleep(100);
} catch (Exception e)
{
}
}
}
} The BB UI supports double buffering or I have to create an auxiliary buffer to draw inside it first and then draw the buffer to the screen in the paint method? Maybe I should make "theGraphics = getGraphics()" somewhere else, like before I call in the draw() method?