Hi everyone,
I'm trying to create a very simple animation applet, but it doesn't seem to be working very well. For some reason, the background color isn't changing and the graphics aren't being drawn to the applet. I think the Thread is also causing some issues. Any help would be greatly appreciated.
import java.awt.*; import javax.swing.*; public class Animation extends JApplet { int x = 10; int y = 10; Drawing d; public void init(){ setSize(500, 500); d = new Drawing(); Container content = getContentPane(); content.add(d, BorderLayout.CENTER); content.setVisible(true); } public void start(){ go(); } public void go(){ for (int i = 0; i < 330; i++){ x++; y++; d.repaint(); try{ Thread.sleep(20); } catch (Exception ex){} } } public class Drawing extends JPanel { public void paintComponent(Graphics g) { super.paint(g); Graphics2D g2 = (Graphics2D) g; this.setBackground(Color.BLACK); g.setColor(Color.ORANGE); g.fillOval(x, y, 30, 30); } } }