Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package KOL;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JApplet;
- /**
- *
- * @author Le MOI
- */
- public class Kol3 extends JApplet implements Runnable{
- int x=0;
- int y=0;
- boolean goRight = true;
- boolean goLeft = false;
- boolean goBottom = false;
- boolean goTop = false;
- public void init(){
- Thread t=new Thread(this);
- t.start();
- setSize(300, 200);
- }
- public void paint(Graphics g){
- super.paint(g);
- //while(x<getWidth()-20){
- pravoagolnik(g, x, y);
- //zmija(g,x,0);
- //}
- }
- public void pravoagolnik(Graphics g,int x,int y){
- g.setColor(Color.BLUE);
- g.fillRect(x, y,20, 20);
- g.setColor(Color.BLACK);
- g.drawRect(x, y,20, 20);
- }
- public void zmija(Graphics g,int xx,int yy){
- xx=0;
- for(int i=xx;i<100;i+=20){
- pravoagolnik(g, i, yy);
- }
- }
- @Override
- public void run() {
- while(true){
- if(goRight){
- if(x+25 > 300){
- goRight = false;
- goBottom = true;
- }else
- x+=5;
- }
- if(goBottom){
- if(y+25 > 200){
- goBottom = false;
- goLeft = true;
- }
- else
- y+=5;
- }
- if(goLeft){
- if(x<0){
- x=0;
- goLeft = false;
- goTop = true;
- }
- else
- x-=5;
- }
- if(goTop){
- if(y<0){
- y=0;
- goTop = false;
- goRight = true;
- }
- else
- y-=5;
- }
- repaint();
- try {
- Thread.sleep(50);
- } catch (InterruptedException ex) {
- // Logger.getLogger(Kol2.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement