Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.87 KB | None | 0 0
  1. /*
  2.  *           Internet Programiranje Labaratoriska vezba broj 5
  3.  *                             Zadaca 1
  4.  *
  5.  */
  6. package labaratoriska_vezba_5;
  7.  
  8. import java.awt.*;
  9. import java.util.logging.Level;
  10. import java.util.logging.Logger;
  11. import javax.swing.JApplet;
  12. import javax.swing.*;
  13. import javax.swing.border.LineBorder;
  14.  
  15. /**
  16.  *
  17.  * @author Aleksandar Babic 137009
  18.  */
  19. public class lab_5_zadaca_1 extends JApplet
  20. {
  21.     private nitka rect=new nitka();  
  22.     @Override
  23.     public void init()
  24.     {
  25.         this.getContentPane().setBackground(Color.YELLOW);
  26.         add(rect);
  27.     }    
  28. }
  29. class nitka extends JLabel implements Runnable
  30. {
  31.     private int x=0;
  32.     private int y=0;
  33.     private int xx=0;
  34.     private int yy=0;
  35.     private int w;
  36.     private int h;
  37.     private Thread t1;
  38.    
  39.     public nitka()
  40.     {
  41.         t1=new Thread(this);
  42.         t1.start();
  43.        
  44.     }                
  45.    @Override
  46.    public void paint(Graphics g)
  47.    {
  48.        super.paint(g);
  49.        w=getWidth();
  50.        h=getHeight();
  51.        g.drawRect(x,y,w/5,h/5);
  52.        g.drawRect(x+w/5,y,w/5,h/5);
  53.        g.drawRect(x+w/5+w/5,y,w/5,h/5);
  54.        g.drawRect(x+w/5+w/5+w/5,y,w/5,h/5);
  55.        g.drawRect(x+w/5+w/5+w/5+w/5,y,w/5,h/5);
  56.        
  57.        g.drawRect(x,y+h/5,w/5,h/5);
  58.        g.drawRect(x+w/5,y+h/5,w/5,h/5);
  59.        g.drawRect(x+w/5+w/5,y+h/5,w/5,h/5);
  60.        g.drawRect(x+w/5+w/5+w/5,y+h/5,w/5,h/5);
  61.        g.drawRect(x+w/5+w/5+w/5+w/5,y+h/5,w/5,h/5);
  62.        
  63.        g.drawRect(x,y+h/5+h/5,w/5,h/5);
  64.        g.drawRect(x+w/5,y+h/5+h/5,w/5,h/5);
  65.        g.drawRect(x+w/5+w/5,y+h/5+h/5,w/5,h/5);
  66.        g.drawRect(x+w/5+w/5+w/5,y+h/5+h/5,w/5,h/5);
  67.        g.drawRect(x+w/5+w/5+w/5+w/5,y+h/5+h/5,w/5,h/5);
  68.        
  69.        g.drawRect(x,y+h/5+h/5+h/5,w/5,h/5);
  70.        g.drawRect(x+w/5,y+h/5+h/5+h/5,w/5,h/5);
  71.        g.drawRect(x+w/5+w/5,y+h/5+h/5+h/5,w/5,h/5);
  72.        g.drawRect(x+w/5+w/5+w/5,y+h/5+h/5+h/5,w/5,h/5);
  73.        g.drawRect(x+w/5+w/5+w/5+w/5,y+h/5+h/5+h/5,w/5,h/5);
  74.        
  75.        g.drawRect(x,y+h/5+h/5+h/5+h/5,w/5,h/5);
  76.        g.drawRect(x+w/5,y+h/5+h/5+h/5+h/5,w/5,h/5);
  77.        g.drawRect(x+w/5+w/5,y+h/5+h/5+h/5+h/5,w/5,h/5);
  78.        g.drawRect(x+w/5+w/5+w/5,y+h/5+h/5+h/5+h/5,w/5,h/5);
  79.        g.drawRect(x+w/5+w/5+w/5+w/5,y+h/5+h/5+h/5+h/5,w/5,h/5);
  80.        
  81.        g.fillRect(xx,yy,w/5,h/5);              
  82.    }
  83.     @Override
  84.     public void run()
  85.     {
  86.         while(true)
  87.         {
  88.             repaint();
  89.             if(xx<w)
  90.             {
  91.                 xx+=w/5;
  92.             }
  93.             else if(xx>=w)
  94.             {
  95.                 xx=0;
  96.                 yy+=h/5;
  97.             }
  98.             if(yy>=h)
  99.             {
  100.                 xx=0;
  101.                 yy=0;
  102.             }                                                
  103.             try {Thread.sleep(500);
  104.             } catch (InterruptedException ex) {}
  105.         }        
  106.     }    
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement