Reputation: 171
Hey I've created a simple Frame that displays the olympic rings but I try to port them to applet without any success. This is the code I'm running:
import java.awt.*;
import javax.swing.*;
public class CirclesApplet extends JApplet {
private static final long serialVersionUID = 1L;
Container c;
public void init(){
c = getContentPane();
c.setSize(300, 300);
c.setBackground(Color.GRAY);
c.setLayout(new FlowLayout());
}
public void paintComponent(Graphics g){
super.paintComponents(g);
g.setColor(Color.BLUE);
g.drawOval(65, 90, 50, 50);
g.setColor(Color.YELLOW);
g.drawOval(95, 110, 50, 50);
g.setColor(Color.BLACK);
g.drawOval(125, 90, 50, 50);
g.setColor(Color.GREEN);
g.drawOval(155, 110, 50, 50);
g.setColor(Color.red);
g.drawOval(180, 90, 50, 50);
g.drawString("Olympic Rings", 120, 185);
}
}
What am I doing wrong?
Upvotes: 0
Views: 114
Reputation: 324197
What am I doing wrong?
There is no paintComponent() method of a JApplet, JFrame or JDialog.
As you know for your other postings you override the paintComponent() method of a panel to do custom painting and then add the panel to the content pane.
A JApplet is no different, it also has a content pane.
Upvotes: 2