Hey guys, I'm for the most part a backend programmer but I'm taking a GUI class as a elective, and I'm haveing some problems with an applet. Part of the assigment is to create a logo design that displays a bunch of pentagons in a circle with different colors and rotating. I made the applet and I was able to run it under my IDE's applet simulator; however, once I throw the code in an html, I get the notinited error. Pretty much all of the work is done in the paint container, and I was under the impression that if all you have is a container in your code, then you do not need to include an init method (I've done it this way before with smaller applets) A friend suggested I might need to include a specific jar file in the html, but he couldn't remember the name of the jar. If thats not the problem then it must mean I would need an init method, but I'm not too sure how to put that in so it works. Any advise would be greatly appreciated.
Here's my code:
import java.awt.*;
import java.awt.geom.GeneralPath;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Color;
import java.util.Random;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Pentagons extends JApplet{
public void init(){
}
public void paint(Graphics g){
super.paint(g);
Random random = new Random();
int xPoints[] = {0, 25, 75, 100, 50};
int yPoints[] = {50, 100, 100, 50, 0};
Graphics2D g2d = (Graphics2D) g;
GeneralPath pentagon = new GeneralPath();
pentagon.moveTo(xPoints[0], yPoints[0]);
for (int count =1; count< xPoints.length; count++)
pentagon.lineTo(xPoints[count], yPoints[count]);
pentagon.closePath();
g2d.translate(200, 200);
for (int i =1; i <= 20; i++){
g2d.rotate(Math.PI/ 10.0);
g2d.setColor(new Color( random.nextInt(256),
random.nextInt(256), random.nextInt(256)));
g2d.fill(pentagon);
}
}
}
thanx
matt