| | |
applet shows notinited error in the web browser
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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:
thanx
matt
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
Java Syntax (Toggle Plain Text)
package projectA; 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 java.jama; import javax.swing.JApplet; import javax.swing.JFrame; import javax.swing.JPanel; public class Pentagons extends JApplet { public int xPoints[] = new int [5]; public int yPoints[] = new int [5]; public void init() { xPoints[0] = 0; xPoints[1] = 25; xPoints[2] = 75; xPoints[3] = 100; xPoints[4] = 50; yPoints[0] = 50; yPoints[1] = 100; yPoints[2] = 100; yPoints[3] = 50; yPoints[4] = 0; } public void paint(Graphics g){ super.paint(g); Random random = new Random(); 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); } } }
Ok, so I got it running, I figure I would post the working code for anyone interested ....
Java Syntax (Toggle Plain Text)
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; public class Pentagons extends JApplet { public int xPoints[] = new int [5]; public int yPoints[] = new int [5]; public Pentagons() { } /**Initialize the applet*/ public void init() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } public void jbInit() { xPoints[0] = 0; xPoints[1] = 25; xPoints[2] = 75; xPoints[3] = 100; xPoints[4] = 50; yPoints[0] = 50; yPoints[1] = 100; yPoints[2] = 100; yPoints[3] = 50; yPoints[4] = 0; } public void paint(Graphics g){ super.paint(g); Random random = new Random(); 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); } } /**Main method*/ public static void main(String[] args) { Pentagons applet = new Pentagons(); applet.init(); applet.start(); } }
![]() |
Similar Threads
- developing a plugin in c++ on linux platformfor a web browser eg. konqueror/ mozilla (C++)
- Pictures not showing up in any web browser!!! (Web Browsers)
- help!..VerySimple web browser(display source code of web pages) (JSP)
- Pc web browser hijacker (Viruses, Spyware and other Nasties)
- Running X apps within a web browser (Darwin, X11 and BSD)
- The best Web Browser Ever (Mac Software)
Other Threads in the Java Forum
- Previous Thread: set time in int
- Next Thread: Some stupid error i cant fix, PLEASE HELP
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary bluetooth character chat class classes client code component consumer csv database desktop eclipse error event exception fractal ftp game givemetehcodez graphics gui html ide image input integer j2me japplet java javaarraylist javac javaee javaprojects jmf jni jpanel julia linked linux list loop mac map method methods mobile netbeans newbie objects online oriented panel print printf problem program programming project projects properties recursion replaydirector reporting researchinmotion robot rotatetext rsa scanner screen se server set size sms sort sql string swing template test threads time tree ubuntu update windows working





