Can someone please help me out here - I’m obviously doing something stupid, but can’t think what and am going round in circles.
This is a simple applet (actually more of a craplet) that should show a red screen, but doesn’t. It’s a simplified version of something bigger that equally doesn’t work.
The applet class:
import javax.swing.*;
import java.awt.*;
public class MyApplet extends JApplet implements Runnable {
MyPanel myPanel;
public void init(){
myPanel=new MyPanel();
this.getContentPane().add(myPanel);
new Thread(this).run();
}
public void run(){
while(true){
myPanel.repaint();
try{Thread.sleep(50);}catch(Exception e){}
}
}
}
and the panel class:
import java.awt.*;
import javax.swing.*;
public class MyPanel extends JPanel {
public void paint(Graphics g){
Graphics2D g2d=(Graphics2D)g;
g2d.setColor(Color.RED);
g2d.fillRect(0, 0, this.getWidth(), this.getHeight());
}
}
Any ideas ?
Thanks