Re: Вопрос новичка
От: Bender Rodriquez Мексика  
Дата: 16.01.06 08:20
Оценка:
Извини, тороплюсь. Но что-то вроде того:

package rct;

import java.awt.*;
import java.applet.*;
import java.util.*;

public class Appl
    extends Applet implements Runnable{

  Color colDraw = Color.BLACK;
  Color colErase = Color.white;

  Thread thrTimer;
  int thrSleepMls = 100;
  
  int iterCur = 0;
  int iterLim = 120;
  
  Rectangle rect = new Rectangle(0,0,1,1); 
  int rectWid = 10;
  int rectHei = 10;

  public Appl() {
  }

  public void init() {
    try {
      jbInit();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void jbInit() throws Exception {
    setBackground(colErase);
  }

  public void start() {
    thrTimer = new Thread(this);
    thrTimer.start();
  }

  public void stop() {
    thrTimer = null;
  }

  public void run() {
    Thread thrThis = Thread.currentThread();
    while(thrThis == thrTimer){
      try{
          Thread.currentThread().sleep(thrSleepMls);
      }catch(InterruptedException exc){
      }
      repaint();
    }
  }

  public void update(Graphics g) {
    paint(g);
  }


  public void drawRect(Graphics g,Rectangle rect, Color col) {
    g.setColor(col);
    Graphics2D g2 = (Graphics2D)g;
    g2.draw(rect);
  }
  

  public void paint(Graphics g) {
    int xCent = 0, yCent = 0;
    int xCur = 0, yCur = 0;
    
    xCent = (int)this.getWidth()/2;
    yCent = (int)this.getHeight()/2;
    
    
     xCur = (int)(Math.cos(iterCur * Math.PI/30 - Math.PI/2) * 45 + xCent);
     yCur = (int)(Math.sin(iterCur * Math.PI/30 - Math.PI/2) * 45 + yCent);
    
    drawRect(g, rect, colErase);
    
     rect.setBounds(xCur, yCur, rectWid, rectHei);
    
    drawRect(g, rect, colDraw);
    
    if(iterCur < iterLim)
      iterCur++;
    else
      iterCur = 0;
  }

}


На столько торопился, что пару лишних кликов забыл. Раскрашено вручную. Blazkowicz.
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.