Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. package lab6;
  2.  
  3. import javax.microedition.lcdui.*;
  4.  
  5. public class MyCanvas extends Canvas implements CommandListener{
  6.  
  7. Midlet midlet;
  8. int xPos;
  9. int yPos;
  10. int kolor;
  11.  
  12. public MyCanvas(Midlet _midlet)
  13. {
  14. midlet = _midlet;
  15. addCommand( new Command( "Koniec", Command.EXIT, 0 ));
  16. setCommandListener(this);
  17. xPos=getWidth()/2;
  18. yPos=getHeight()/2;
  19. }
  20.  
  21. protected void paint(Graphics g) {
  22. g.setColor(0xffffff);
  23. int screenWidth =getWidth();
  24. int screenHeight=getHeight();
  25. g.fillRect(0,0,screenWidth,screenHeight);
  26. g.setColor(kolor,kolor,kolor);
  27. g.fillRect(xPos,yPos,32,32);
  28. System.out.println("repaint");
  29. }
  30. protected void keyPressed(int keyCode)
  31. {
  32. switch(keyCode)
  33. {
  34. case KEY_NUM2:--yPos;
  35. kolor=50;
  36. break;
  37. case KEY_NUM8:++yPos;
  38. kolor=100;
  39. break;
  40. case KEY_NUM4:--xPos;
  41. kolor=150;
  42. break;
  43. case KEY_NUM6:++xPos;
  44. kolor=200;
  45. break;
  46. }
  47. repaint();
  48. serviceRepaints();
  49. }
  50. public void commandAction(Command c, Displayable d)
  51. {
  52. switch(c.getCommandType()) {
  53. case Command.EXIT:
  54. midlet.destroyApp( false );
  55. midlet.notifyDestroyed();
  56. break;
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement