123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- /*
- * 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.util.logging.Logger;
- import javax.swing.JComponent;
-
- /**
- *
- * @author le
- */
- public class Kreis extends JComponent implements Runnable
- {
- private Ellipse2D.Float kreis;
- private BasicStroke pinsel;
- private float radius;
- private float minRadius;
- private float maxRadius;
- private Thread thd;
- private long schlafzeit;
- private static final float DICKE = 8f;
- private static Logger lg = Logger.getLogger("grafik");
-
- public Kreis(long schlafzeit)
- {
- this.schlafzeit = schlafzeit;
- minRadius = DICKE;
- maxRadius = 100;
- kreis = new Ellipse2D.Float();
- pinsel = new BasicStroke(DICKE);
- radius = 10;
- 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;
-
- kreis.setFrame(x, y, radius*2, radius*2);
-
- g2.setStroke(pinsel);
- // g2.setPaint(Color.RED);
- // g2.fill(kreis);
- g2.setPaint(Color.BLACK);
- g2.draw(kreis);
-
- }
-
- @Override
- public void run()
- {
- float delta = 1f;
- while (true)
- {
- if (radius > maxRadius) delta = -1f;
- if (radius < minRadius) delta = +1f;
- radius += delta;
- this.repaint();
- try
- {
- Thread.sleep(schlafzeit);
- }
- catch (InterruptedException iex)
- {
- lg.warning(iex.toString());
- }
- }
- }
-
- }
|