Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. package KOL;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.util.logging.Level;
  6. import java.util.logging.Logger;
  7. import javax.swing.JApplet;
  8.  
  9. /**
  10. *
  11. * @author Le MOI
  12. */
  13. public class Kol3 extends JApplet implements Runnable{
  14.  
  15. int x=0;
  16. int y=0;
  17. boolean goRight = true;
  18. boolean goLeft = false;
  19. boolean goBottom = false;
  20. boolean goTop = false;
  21.  
  22. public void init(){
  23. Thread t=new Thread(this);
  24. t.start();
  25. setSize(300, 200);
  26. }
  27.  
  28. public void paint(Graphics g){
  29. super.paint(g);
  30.  
  31. //while(x<getWidth()-20){
  32. pravoagolnik(g, x, y);
  33. //zmija(g,x,0);
  34. //}
  35.  
  36. }
  37.  
  38. public void pravoagolnik(Graphics g,int x,int y){
  39. g.setColor(Color.BLUE);
  40. g.fillRect(x, y,20, 20);
  41. g.setColor(Color.BLACK);
  42. g.drawRect(x, y,20, 20);
  43. }
  44.  
  45. public void zmija(Graphics g,int xx,int yy){
  46. xx=0;
  47. for(int i=xx;i<100;i+=20){
  48. pravoagolnik(g, i, yy);
  49. }
  50. }
  51.  
  52. @Override
  53. public void run() {
  54. while(true){
  55.  
  56. if(goRight){
  57. if(x+25 > 300){
  58. goRight = false;
  59. goBottom = true;
  60. }else
  61. x+=5;
  62. }
  63. if(goBottom){
  64. if(y+25 > 200){
  65. goBottom = false;
  66. goLeft = true;
  67. }
  68. else
  69. y+=5;
  70. }
  71. if(goLeft){
  72. if(x<0){
  73. x=0;
  74. goLeft = false;
  75. goTop = true;
  76. }
  77. else
  78. x-=5;
  79. }
  80. if(goTop){
  81. if(y<0){
  82. y=0;
  83. goTop = false;
  84. goRight = true;
  85. }
  86. else
  87. y-=5;
  88. }
  89. repaint();
  90. try {
  91. Thread.sleep(50);
  92. } catch (InterruptedException ex) {
  93. // Logger.getLogger(Kol2.class.getName()).log(Level.SEVERE, null, ex);
  94. }
  95. }
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement