M
MM
Gast
Hallo
Warum funktioniert dass nicht.
MFG
Exodus
Warum funktioniert dass nicht.
Code:
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.geom.Arc2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
class Zeichnung extends JPanel implements Runnable
{
double w = 50;
double x = 50;
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
Shape arc = new Arc2D.Double(w,x,60,60,30,120,Arc2D.PIE);
((Graphics2D)g).draw(arc);
}
public void run() {
while(true)
{
repaint();
try
{
w++;
System.out.println(w);
Thread.sleep (20);
}
catch (InterruptedException e)
{
}
}
}
}
public class test{
public static void main (String[] args)
{
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(500,500);
f.setVisible(true);
f.add(new Zeichnung());
final Thread t1 = new Thread(new Zeichnung());
f.addKeyListener(new KeyListener()
{
public void keyPressed(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.VK_LEFT)
{
t1.start();
}
}
public void keyReleased(KeyEvent VK_LEFT) {
}
public void keyTyped(KeyEvent VK_LEFT) {
}
});
}
}
MFG
Exodus