Browse Source

kleine verschönerungen

master
ahren 11 months 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

@@ -21,7 +21,6 @@ public class Start
JFrame frm = new JFrame();
frm.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Container c = frm.getContentPane();
c.setLayout(new OverlayLayout(c));
for (int zeigerLaenge = 1; zeigerLaenge <=3; zeigerLaenge++)
{

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

@@ -15,6 +15,7 @@ import static java.lang.Math.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.logging.Logger;
import javax.swing.JComponent;

/**
@@ -23,10 +24,11 @@ import javax.swing.JComponent;
*/
public class Zeiger extends JComponent implements Runnable
{
private Logger lg = Logger.getLogger("grafik");
private static final float DICKE = 4f;
private Line2D.Float linie;
private BasicStroke stift;
private volatile float radius;
private volatile double radius;
private volatile float xMitte;
private volatile float yMitte;
private volatile double xAussen;
@@ -56,7 +58,7 @@ public class Zeiger extends JComponent implements Runnable
{
synchronized(this)
{
alpha += 0.1;
alpha += 0.08;
xAussen = xMitte +cos(2*PI*alpha) * radius;
yAussen = yMitte + sin(2*PI*alpha) * radius;
}
@@ -67,7 +69,7 @@ public class Zeiger extends JComponent implements Runnable
}
catch (Exception ex)
{
//lg.severe(ex.toString());
lg.severe(ex.toString());
}
}
}
@@ -85,19 +87,21 @@ public class Zeiger extends JComponent implements Runnable
super.paintComponent(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 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;
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);

Loading…
Cancel
Save