Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab6;
- import javax.microedition.lcdui.*;
- public class MyCanvas extends Canvas implements CommandListener{
- Midlet midlet;
- int xPos;
- int yPos;
- int kolor;
- public MyCanvas(Midlet _midlet)
- {
- midlet = _midlet;
- addCommand( new Command( "Koniec", Command.EXIT, 0 ));
- setCommandListener(this);
- xPos=getWidth()/2;
- yPos=getHeight()/2;
- }
- protected void paint(Graphics g) {
- g.setColor(0xffffff);
- int screenWidth =getWidth();
- int screenHeight=getHeight();
- g.fillRect(0,0,screenWidth,screenHeight);
- g.setColor(kolor,kolor,kolor);
- g.fillRect(xPos,yPos,32,32);
- System.out.println("repaint");
- }
- protected void keyPressed(int keyCode)
- {
- switch(keyCode)
- {
- case KEY_NUM2:--yPos;
- kolor=50;
- break;
- case KEY_NUM8:++yPos;
- kolor=100;
- break;
- case KEY_NUM4:--xPos;
- kolor=150;
- break;
- case KEY_NUM6:++xPos;
- kolor=200;
- break;
- }
- repaint();
- serviceRepaints();
- }
- public void commandAction(Command c, Displayable d)
- {
- switch(c.getCommandType()) {
- case Command.EXIT:
- midlet.destroyApp( false );
- midlet.notifyDestroyed();
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement