Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Internet Programiranje Labaratoriska vezba broj 5
- * Zadaca 1
- *
- */
- package labaratoriska_vezba_5;
- import java.awt.*;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JApplet;
- import javax.swing.*;
- import javax.swing.border.LineBorder;
- /**
- *
- * @author Aleksandar Babic 137009
- */
- public class lab_5_zadaca_1 extends JApplet
- {
- private nitka rect=new nitka();
- @Override
- public void init()
- {
- this.getContentPane().setBackground(Color.YELLOW);
- add(rect);
- }
- }
- class nitka extends JLabel implements Runnable
- {
- private int x=0;
- private int y=0;
- private int xx=0;
- private int yy=0;
- private int w;
- private int h;
- private Thread t1;
- public nitka()
- {
- t1=new Thread(this);
- t1.start();
- }
- @Override
- public void paint(Graphics g)
- {
- super.paint(g);
- w=getWidth();
- h=getHeight();
- g.drawRect(x,y,w/5,h/5);
- g.drawRect(x+w/5,y,w/5,h/5);
- g.drawRect(x+w/5+w/5,y,w/5,h/5);
- g.drawRect(x+w/5+w/5+w/5,y,w/5,h/5);
- g.drawRect(x+w/5+w/5+w/5+w/5,y,w/5,h/5);
- g.drawRect(x,y+h/5,w/5,h/5);
- g.drawRect(x+w/5,y+h/5,w/5,h/5);
- g.drawRect(x+w/5+w/5,y+h/5,w/5,h/5);
- g.drawRect(x+w/5+w/5+w/5,y+h/5,w/5,h/5);
- g.drawRect(x+w/5+w/5+w/5+w/5,y+h/5,w/5,h/5);
- g.drawRect(x,y+h/5+h/5,w/5,h/5);
- g.drawRect(x+w/5,y+h/5+h/5,w/5,h/5);
- g.drawRect(x+w/5+w/5,y+h/5+h/5,w/5,h/5);
- g.drawRect(x+w/5+w/5+w/5,y+h/5+h/5,w/5,h/5);
- g.drawRect(x+w/5+w/5+w/5+w/5,y+h/5+h/5,w/5,h/5);
- g.drawRect(x,y+h/5+h/5+h/5,w/5,h/5);
- g.drawRect(x+w/5,y+h/5+h/5+h/5,w/5,h/5);
- g.drawRect(x+w/5+w/5,y+h/5+h/5+h/5,w/5,h/5);
- g.drawRect(x+w/5+w/5+w/5,y+h/5+h/5+h/5,w/5,h/5);
- g.drawRect(x+w/5+w/5+w/5+w/5,y+h/5+h/5+h/5,w/5,h/5);
- g.drawRect(x,y+h/5+h/5+h/5+h/5,w/5,h/5);
- g.drawRect(x+w/5,y+h/5+h/5+h/5+h/5,w/5,h/5);
- g.drawRect(x+w/5+w/5,y+h/5+h/5+h/5+h/5,w/5,h/5);
- g.drawRect(x+w/5+w/5+w/5,y+h/5+h/5+h/5+h/5,w/5,h/5);
- g.drawRect(x+w/5+w/5+w/5+w/5,y+h/5+h/5+h/5+h/5,w/5,h/5);
- g.fillRect(xx,yy,w/5,h/5);
- }
- @Override
- public void run()
- {
- while(true)
- {
- repaint();
- if(xx<w)
- {
- xx+=w/5;
- }
- else if(xx>=w)
- {
- xx=0;
- yy+=h/5;
- }
- if(yy>=h)
- {
- xx=0;
- yy=0;
- }
- try {Thread.sleep(500);
- } catch (InterruptedException ex) {}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement