Advertisement
Guest User

zad1

a guest
Nov 23rd, 2014
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package lab5_ip;
  6.  
  7. import java.awt.Color;
  8. import java.awt.Graphics;
  9. import java.util.logging.Level;
  10. import java.util.logging.Logger;
  11. import javax.swing.*;
  12.  
  13. /**
  14. *
  15. * @author Slobodanka
  16. */
  17. public class zadaca1 extends JApplet implements Runnable {
  18.  
  19. public int x=0,y=0;
  20.  
  21. public void init() {
  22. Thread t=new Thread(this);
  23. t.start();
  24. }
  25.  
  26.  
  27. @Override
  28. public void run() {
  29. while(true){
  30. if(x<getWidth()){
  31. x+=(getWidth()/5);
  32. }
  33. else{
  34. x=0;
  35. if(y<getHeight()){
  36. y+=(getHeight()/5);
  37. }
  38. else{
  39. y=0;
  40. }
  41. }
  42. repaint();
  43.  
  44. try {
  45. Thread.sleep(1000);
  46. } catch (InterruptedException ex) {
  47. Logger.getLogger(zadaca1.class.getName()).log(Level.SEVERE, null, ex);
  48. }
  49. }
  50. }
  51.  
  52. @Override
  53. public void paint(Graphics g){
  54. g.setColor(Color.YELLOW);
  55. g.fillRect(0,0,getWidth(), getHeight());
  56. g.setColor(Color.BLACK);
  57. for(int i=0;i<getWidth();i+=getWidth()/5) {
  58. for(int j=0;j<getHeight();j+=getHeight()/5){
  59. g.drawRect(i, j, getWidth()/5, getHeight()/5);
  60. }
  61. }
  62. g.setColor(Color.BLACK);
  63. g.fillRect(x, y, getWidth()/5, getHeight()/5);
  64.  
  65.  
  66.  
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement