/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mobileapplication11;
import java.util.Random;
import javax.microedition.lcdui.*;
public class MyCanvas
extends Canvas implements CommandListener
{
Midlet midlet;
int xPos;
int yPos;
int rColor;
int gColor;
int bColor;
boolean key_command[];
public MyCanvas(Midlet _midlet) {
midlet = _midlet;
key_command = new boolean[4];
for (int i = 0; i < 4; i++) {
key_command[i] = false;
}
addCommand(new Command("Koniec", Command.EXIT, 0));
setCommandListener(this);
xPos = getWidth() / 2;
yPos = getHeight() / 2;
rColor = 10;
gColor = 10;
bColor = 255;
}
int r = generator.nextInt(4);
g.setColor(0xffffff);
int screenWidth = getWidth();
int screenHeight = getHeight();
g.fillRect(0, 0, screenWidth, screenHeight);
g.setColor(rColor, gColor, bColor);
g.fillRect(xPos, yPos, 32, 32);
System.
out.
println("repaint");
moveRectangle(r);
}
public void commandAction(Command c, Displayable d) {
switch (c.getCommandType()) {
case Command.EXIT:
midlet.destroyApp(false);
midlet.notifyDestroyed();
break;
}
}
private void moveRectangle(int r) {
while (yPos > 0 && yPos < getHeight() && xPos > 0 && xPos < getWidth()) {
switch (r) {
case 0:
--yPos;
break;
case 1:
++yPos;
break;
case 2:
--xPos;
break;
case 3:
++xPos;
break;
}
repaint();
serviceRepaints();
}
}
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}