applet shows notinited error in the web browser

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2005
Posts: 21
Reputation: higherGround574 is an unknown quantity at this point 
Solved Threads: 0
higherGround574's Avatar
higherGround574 higherGround574 is offline Offline
Newbie Poster

applet shows notinited error in the web browser

 
0
  #1
Oct 4th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 21
Reputation: higherGround574 is an unknown quantity at this point 
Solved Threads: 0
higherGround574's Avatar
higherGround574 higherGround574 is offline Offline
Newbie Poster

Re: applet shows notinited error in the web browser

 
0
  #2
Oct 9th, 2006
  1. package projectA;
  2.  
  3.  
  4.  
  5. import java.awt.*;
  6. import java.awt.geom.GeneralPath;
  7. import java.awt.Graphics;
  8. import java.awt.Graphics2D;
  9. import java.awt.Color;
  10. import java.util.Random;
  11. import java.jama;
  12. import javax.swing.JApplet;
  13. import javax.swing.JFrame;
  14. import javax.swing.JPanel;
  15. public class Pentagons extends JApplet {
  16. public int xPoints[] = new int [5];
  17. public int yPoints[] = new int [5];
  18.  
  19. public void init() {
  20. xPoints[0] = 0;
  21. xPoints[1] = 25;
  22. xPoints[2] = 75;
  23. xPoints[3] = 100;
  24. xPoints[4] = 50;
  25. yPoints[0] = 50;
  26. yPoints[1] = 100;
  27. yPoints[2] = 100;
  28. yPoints[3] = 50;
  29. yPoints[4] = 0;
  30. }
  31. public void paint(Graphics g){
  32. super.paint(g);
  33. Random random = new Random();
  34.  
  35.  
  36. Graphics2D g2d = (Graphics2D) g;
  37. GeneralPath pentagon = new GeneralPath();
  38. pentagon.moveTo(xPoints[0], yPoints[0]);
  39.  
  40. for (int count =1; count< xPoints.length; count++)
  41. pentagon.lineTo(xPoints[count], yPoints[count]);
  42. pentagon.closePath();
  43. g2d.translate(200, 200);
  44. for (int i =1; i <= 20; i++){
  45.  
  46. g2d.rotate(Math.PI/ 10.0);
  47. g2d.setColor(new Color( random.nextInt(256),
  48. random.nextInt(256), random.nextInt(256)));
  49. g2d.fill(pentagon);
  50.  
  51. }
  52.  
  53. }
  54. }
Ok so I've tried a few more things with this and included a init() method but I'm still getting the same error, and now I'm really out of ideas... anyone have any thoughts please let me know ... i need some more things to try ... thanx
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 21
Reputation: higherGround574 is an unknown quantity at this point 
Solved Threads: 0
higherGround574's Avatar
higherGround574 higherGround574 is offline Offline
Newbie Poster

Re: applet shows notinited error in the web browser

 
0
  #3
Oct 11th, 2006
Ok, so I got it running, I figure I would post the working code for anyone interested ....
  1. import java.awt.*;
  2. import java.awt.geom.GeneralPath;
  3. import java.awt.Graphics;
  4. import java.awt.Graphics2D;
  5. import java.awt.Color;
  6. import java.util.Random;
  7. import javax.swing.JApplet;
  8.  
  9. public class Pentagons extends JApplet {
  10.  
  11. public int xPoints[] = new int [5];
  12. public int yPoints[] = new int [5];
  13.  
  14. public Pentagons() {
  15. }
  16. /**Initialize the applet*/
  17.  
  18. public void init() {
  19. try {
  20. jbInit();
  21. }
  22. catch(Exception e) {
  23. e.printStackTrace();
  24. }
  25. }
  26.  
  27. public void jbInit() {
  28. xPoints[0] = 0;
  29. xPoints[1] = 25;
  30. xPoints[2] = 75;
  31. xPoints[3] = 100;
  32. xPoints[4] = 50;
  33. yPoints[0] = 50;
  34. yPoints[1] = 100;
  35. yPoints[2] = 100;
  36. yPoints[3] = 50;
  37. yPoints[4] = 0;
  38. }
  39.  
  40. public void paint(Graphics g){
  41. super.paint(g);
  42. Random random = new Random();
  43.  
  44.  
  45. Graphics2D g2d = (Graphics2D) g;
  46. GeneralPath pentagon = new GeneralPath();
  47. pentagon.moveTo(xPoints[0], yPoints[0]);
  48.  
  49. for (int count =1; count< xPoints.length; count++)
  50. pentagon.lineTo(xPoints[count], yPoints[count]);
  51. pentagon.closePath();
  52. g2d.translate(200, 200);
  53. for (int i =1; i <= 20; i++){
  54.  
  55. g2d.rotate(Math.PI/ 10.0);
  56. g2d.setColor(new Color( random.nextInt(256),
  57. random.nextInt(256), random.nextInt(256)));
  58. g2d.fill(pentagon);
  59.  
  60. }
  61. }
  62.  
  63. /**Main method*/
  64. public static void main(String[] args) {
  65. Pentagons applet = new Pentagons();
  66. applet.init();
  67. applet.start();
  68. }
  69.  
  70. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC