Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
import java.awt.*;
import javax.swing.*;
public class Test {
static class Leinwand extends JComponent {
int largeHalfAxis = 50;
int smallHalfAxis = 25;
int knobRadius = 3;
double knobAngle = 0;
public void setAngle(double angle) {
knobAngle = angle;
repaint();
}
public double getAngle() { return knobAngle; }
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
int cx = this.getWidth() / 2;
int cy = this.getHeight() / 2;
g.setColor(Color.RED);
g.drawOval(cx - largeHalfAxis, cy - smallHalfAxis, 2*largeHalfAxis, 2*smallHalfAxis);
int x = (int) (largeHalfAxis*Math.cos(knobAngle));
int y = (int) (smallHalfAxis*Math.sin(knobAngle));
g.setColor(Color.magenta);
g.fillOval(cx - x - knobRadius, cy - y - knobRadius, 2*knobRadius, 2*knobRadius);
}
}
public void run() {
Leinwand leinwand = new Leinwand();
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(leinwand);
frame.setSize(800, 600);
frame.setVisible(true);
final long start = System.currentTimeMillis();
Timer t = new Timer(30, e -> {
long diff = (System.currentTimeMillis() - start) % 2000;
leinwand.setAngle(diff*2*Math.PI/2000.0);
});
t.start();
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> new Test().run());
}
}