1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
|
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import javax.swing.JFrame;
public class GUI extends JFrame
{
public GUI()
{
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Fenster");
this.setSize(1000, 1000);
this.setLocation(20, 20);
this.setLayout(new FlowLayout());
this.setVisible(true);
}
private PENDEL pendel;
public void zeichnen(PENDEL pendel)
{
this.pendel = pendel;
Graphics g = GUI.this.getGraphics();
GUI.this.paint(g);
}
public void paint(Graphics g)
{
int x0 = 200;
int y0 = 200;
int x1 = (int) (pendel.getX() * 500 + x0);
int y1 = (int) (-pendel.getY() * 500 + y0);
g.setColor(Color.white);
g.fillRect(-1, -1, 1000, 1000);
g.setColor(Color.black);
g.drawLine(x0, y0, x1, y1);
g.fillOval(x0 - 5, y0 - 5, 10, 10);
g.setColor(Color.blue);
g.fillOval(x1 - 5, y1 - 5, 10, 10);
}
} |