/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package grafik2d; /** * * @author nobody */ import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.geom.Ellipse2D; import java.awt.geom.Line2D; import java.util.logging.Logger; import javax.swing.JComponent; /** * * @author le */ public class Gerademitsincos extends JComponent implements Runnable { private Ellipse2D.Float Kreis; private Line2D.Float Gerade; private BasicStroke pinsel; private float radius; private Thread thd; private long schlafzeit; private static final float DICKE = 2f; private static Logger lg = Logger.getLogger("grafik"); private static float xmittel,ymittel; private float deltax, deltay; public Gerademitsincos(long schlafzeit, int zeit) { this.schlafzeit = schlafzeit; Kreis = new Ellipse2D.Float(); pinsel = new BasicStroke(DICKE); radius = 100; Gerade = new Line2D.Float(); deltax = 0; deltay = 0; thd = null; } public void start() { if (thd == null) { thd = new Thread(this); thd.start(); } } @Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int breite = this.getWidth() - 1; int hoehe = this.getHeight() - 1; //maxRadius = -DICKE/2f + Math.min(breite/2f, hoehe/2f); float x = breite/2f - radius; float y = hoehe/2f - radius; xmittel = x+radius; ymittel = y+radius; Kreis.setFrame(x, y, radius*2, radius*2); Gerade.setLine(xmittel, ymittel, xmittel -deltax, ymittel -deltay); g2.setStroke(pinsel); g2.setPaint(Color.BLACK); g2.draw(Kreis); g2.draw(Gerade); } @Override public void run() { float delta = 0f; while (true) { deltax = (float) (radius * Math.sin(Math.toRadians(delta))); deltay = (float) (radius * Math.cos(Math.toRadians(delta))); delta -= 6f; System.out.println(delta); this.repaint(); try { Thread.sleep(schlafzeit); } catch (InterruptedException iex) { lg.warning(iex.toString()); } } } }