Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package lab5_ip;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.*;
- /**
- *
- * @author Slobodanka
- */
- public class zadaca1 extends JApplet implements Runnable {
- public int x=0,y=0;
- public void init() {
- Thread t=new Thread(this);
- t.start();
- }
- @Override
- public void run() {
- while(true){
- if(x<getWidth()){
- x+=(getWidth()/5);
- }
- else{
- x=0;
- if(y<getHeight()){
- y+=(getHeight()/5);
- }
- else{
- y=0;
- }
- }
- repaint();
- try {
- Thread.sleep(1000);
- } catch (InterruptedException ex) {
- Logger.getLogger(zadaca1.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- @Override
- public void paint(Graphics g){
- g.setColor(Color.YELLOW);
- g.fillRect(0,0,getWidth(), getHeight());
- g.setColor(Color.BLACK);
- for(int i=0;i<getWidth();i+=getWidth()/5) {
- for(int j=0;j<getHeight();j+=getHeight()/5){
- g.drawRect(i, j, getWidth()/5, getHeight()/5);
- }
- }
- g.setColor(Color.BLACK);
- g.fillRect(x, y, getWidth()/5, getHeight()/5);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement