/* * 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 grafik; import grafik.logger.OhmLogger; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.geom.AffineTransform; import java.awt.geom.Ellipse2D; import java.awt.geom.Line2D; import java.util.logging.Logger; import javax.swing.JComponent; /** * * @author le */ public class Gerade extends JComponent implements Runnable { private Line2D.Double line; private BasicStroke pinsel; private float angle; private float radius; private Thread thd; private long sleepTime; private static final float DICKE = 8f; private static Logger lg = OhmLogger.getLogger(); private float x1, x2, y1, y2; public Gerade(long sleepTime) { this.sleepTime = sleepTime; line = new Line2D.Double(); angle = 0; radius = 100; pinsel = new BasicStroke(DICKE); thd = null; start(); } public void start() { if (thd == null) { lg.info("start"); 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; x1 = breite/2f; y1 = hoehe/2f; /** Rotate with Angle, sin and cos */ // x2 = (float) (radius * Math.cos((2 * Math.PI * angle) / 360) + x1); // y2 = (float) (radius * Math.sin((2 * Math.PI * angle) / 360) + y1); line.setLine(x1, y1, x2, y2); /** Rotate with transforms */ g2.translate(x1, y1); g2.rotate(Math.toRadians(angle)); g2.setStroke(pinsel); g2.setPaint(Color.RED); g2.fill(line); g2.setPaint(Color.BLACK); g2.draw(line); } @Override public void run() { while (true) { if(angle >= 360){ angle = 0; } else { angle += 1; } // if (radius > maxRadius) delta = -1f; // if (radius < minRadius) delta = +1f; // radius += delta; this.repaint(); try { Thread.sleep(sleepTime); } catch (InterruptedException iex) { lg.warning(iex.toString()); } } } }