123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- /*
- * 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());
- }
- }
- }
-
- }
|