Browse Source

kleine verschönerungen

master
ahren 1 year ago
parent
commit
416f890de2
2 changed files with 13 additions and 10 deletions
  1. 0
    1
      src/aufgabe8_grafik2d/Start.java
  2. 13
    9
      src/aufgabe8_grafik2d/Zeiger.java

+ 0
- 1
src/aufgabe8_grafik2d/Start.java View File

JFrame frm = new JFrame(); JFrame frm = new JFrame();
frm.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frm.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Container c = frm.getContentPane(); Container c = frm.getContentPane();
c.setLayout(new OverlayLayout(c)); c.setLayout(new OverlayLayout(c));
for (int zeigerLaenge = 1; zeigerLaenge <=3; zeigerLaenge++) for (int zeigerLaenge = 1; zeigerLaenge <=3; zeigerLaenge++)
{ {

+ 13
- 9
src/aufgabe8_grafik2d/Zeiger.java View File

import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.logging.Logger;
import javax.swing.JComponent; import javax.swing.JComponent;


/** /**
*/ */
public class Zeiger extends JComponent implements Runnable public class Zeiger extends JComponent implements Runnable
{ {
private Logger lg = Logger.getLogger("grafik");
private static final float DICKE = 4f; private static final float DICKE = 4f;
private Line2D.Float linie; private Line2D.Float linie;
private BasicStroke stift; private BasicStroke stift;
private volatile float radius;
private volatile double radius;
private volatile float xMitte; private volatile float xMitte;
private volatile float yMitte; private volatile float yMitte;
private volatile double xAussen; private volatile double xAussen;
{ {
synchronized(this) synchronized(this)
{ {
alpha += 0.1;
alpha += 0.08;
xAussen = xMitte +cos(2*PI*alpha) * radius; xAussen = xMitte +cos(2*PI*alpha) * radius;
yAussen = yMitte + sin(2*PI*alpha) * radius; yAussen = yMitte + sin(2*PI*alpha) * radius;
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
//lg.severe(ex.toString());
lg.severe(ex.toString());
} }
} }
} }
super.paintComponent(g); super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g; Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
float breite = this.getWidth() - 1; float breite = this.getWidth() - 1;
float hoehe = this.getHeight() - 1; float hoehe = this.getHeight() - 1;

float radius = (min(hoehe, breite)/2 - 50) * 1/ zeigerlaenge;
radius = (min(hoehe, breite)/2 *0.9) * 1/ zeigerlaenge;
xMitte = breite/2; xMitte = breite/2;
yMitte = hoehe/2; yMitte = hoehe/2;
xAussen = xMitte +cos(2*PI*alpha) * radius;
yAussen = yMitte + sin(2*PI*alpha) * radius;
synchronized(this)
{
xAussen = xMitte +cos(2*PI*alpha) * radius;
yAussen = yMitte + sin(2*PI*alpha) * radius;
}
linie.setLine(xMitte, yMitte, xAussen, yAussen); linie.setLine(xMitte, yMitte, xAussen, yAussen);

Loading…
Cancel
Save