Hey Everybody,

I'm making a Java applet and trying to post it online. Whenever I open the HTML page where the applet is, i get an error message.

Here's the website with the applet on it:
Applet Website Link

Thanks in advanced,
C++

tonakai, THANK YOU!!!

server_crash, that is my website - do u like it?

srry 2 double post, but:

tonakai, it worked but the applet freezes on the last JOptionPane screen. Here's my code:

import java.awt.Graphics;
import javax.swing.*;
import java.awt.*;

public class quiz extends JApplet
{
  double t;
  int corCount;
  String input1;
  String input2;
  String input3;
  String input4;
  String input5;
  String input6;
  String input7;
  String input8;
  String input9;
  String input10;


  public void init(){

try{
      JOptionPane.showMessageDialog(null,
                                    "Welcome to the quiz.\n\n" +
          "For multiple choice questions, enter the best LETTER.\n" +
          "For true / false quetions, enter 'T' or 'F'.\n\n" +
          "This quiz consists of 10 questions.",
          "R E A D    T H I S    M E S S A G E !",
          JOptionPane.WARNING_MESSAGE);

      input1 = JOptionPane.showInputDialog(null,
                                           "True or False:\n" +
          "Cancer cells can mutilate and become resistent to\n" +
          "chemotherapy drugs.\n", "TRUE OR FALSE ('T' or 'F')",
          JOptionPane.INFORMATION_MESSAGE);

      if (input1.equals("T") || input1.equals("t")) {
        corCount++;
      }

      input2 = JOptionPane.showInputDialog(null,
                                           "Multiple Choice:\n" +
          "Ectoderm gives rise to which of the following:\n\n" +
          "A  nerve+skin\n" +
          "B  internal organs\n" +
          "C  muscles and bone\n" +
          "D  all of the above\n",
          "Multiple Choice",
          JOptionPane.INFORMATION_MESSAGE);

      if (input2.equals("A") || input2.equals("a")) {
        corCount++;
      }

      input3 = JOptionPane.showInputDialog(null,
                                           "True or False:\n" +
          "The hair-like structures covering the\n" +
          "paramicium are flagella.\n", "TRUE OR FALSE ('T' or 'F')",
          JOptionPane.INFORMATION_MESSAGE);

      if (input3.equals("F") || input3.equals("f")) {
        corCount++;
      }

      input4 = JOptionPane.showInputDialog(null,
                                           "True or False:\n" +
          "The chloroplast detects light in a euglena.\n"
          , "TRUE OR FALSE ('T' or 'F')",
          JOptionPane.INFORMATION_MESSAGE);

      if (input4.equals("F") || input4.equals("f")) {
        corCount++;
      }

      input5 = JOptionPane.showInputDialog(null,
                                           "Multiple Choice:\n" +
          "While cloning, a specialized cell nucleus is inserted into:\n\n" +
          "A  another specialized cell\n" +
          "B  a normal egg\n" +
          "C  an egg that had its nucleus removed\n" +
          "D  the uterus of a female\n",
          "Multiple Choice",
          JOptionPane.INFORMATION_MESSAGE);

      if (input5.equals("C") || input5.equals("c")) {
        corCount++;
      }

      input6 = JOptionPane.showInputDialog(null,
                                           "True or False:\n" +
                                           "100,000,000,000 neurons are in a piece of tissue the size of a grain of rice.\n"
                                           , "TRUE OR FALSE ('T' or 'F')",
                                           JOptionPane.INFORMATION_MESSAGE);

      if (input6.equals("F") || input6.equals("f")) {
        corCount++;
      }

      input7 = JOptionPane.showInputDialog(null,
                                           "True or False:\n" +
          "The PR is in the bottom of the bud of the hand.\n"
          , "TRUE OR FALSE ('T' or 'F')",
          JOptionPane.INFORMATION_MESSAGE);

      if (input7.equals("T") || input7.equals("t")) {
        corCount++;
      }

      input8 = JOptionPane.showInputDialog(null,
                                           "True or False:\n" +
          "The SRC gene is the key to determining gender.\n"
          , "TRUE OR FALSE ('T' or 'F')",
          JOptionPane.INFORMATION_MESSAGE);

      if (input8.equals("F") || input8.equals("f")) {
        corCount++;
      }

      input9 = JOptionPane.showInputDialog(null,
                                           "True or False:\n" +
          "Select the gene rules of pairing.\n\n" +
          "A  T,C and A,G\n" +
          "B  A,T and G,C\n" +
          "C  T,G and A,C\n" +
          "D  both b and c\n"
          , "TRUE OR FALSE ('T' or 'F')",
          JOptionPane.INFORMATION_MESSAGE);

      if (input9.equals("B") || input9.equals("b")) {
        corCount++;
      }

      input10 = JOptionPane.showInputDialog(null,
                                            "True or False:\n" +
          "Cells need glucose to construct new parts.\n"
          , "TRUE OR FALSE ('T' or 'F')",
          JOptionPane.INFORMATION_MESSAGE);

      if (input10.equals("T") || input10.equals("t")) {
        corCount++;
      }

      if (corCount >= 8) {
        JOptionPane.showMessageDialog(null,
                                      "\nNumber Correct: " + corCount + " / 10",
                                      "Congratulations!!!",
                                      JOptionPane.INFORMATION_MESSAGE);
      }
      else if (corCount >= 5) {
        JOptionPane.showMessageDialog(null,
                                      "\nNumber Correct: " + corCount + " / 10",
                                      "Better Luck Next Time...",
                                      JOptionPane.INFORMATION_MESSAGE);
      }
      else {
        JOptionPane.showMessageDialog(null,
                                      "\nNumber Correct: " + corCount + " / 10",
                                      "Go Back to Preschool",
                                      JOptionPane.INFORMATION_MESSAGE);
      }
    }
    catch(Exception e){

    }

  }

  public void nothing(){
    try{
    //this method halts the program - does nothing, hence the name nothing
    }
    catch(Exception e3){

    }
  }

  public void paint(Graphics g)
  {
    super.paint(g);
    try{

      g.setFont(new Font("arial", Font.BOLD, 16));

      g.drawString(" Q U I Z ! ! ! ", 115, 15);
      g.drawRoundRect(45, 30, 270, 20, 15, 15);

      g.setFont(new Font("arial", Font.BOLD + Font.ITALIC, 14));

      g.drawString("Questions Correct:   " + corCount + " out of 10", 50, 45);

      g.setFont(new Font("arial", Font.PLAIN, 12));

      g.drawString("Your Input:", 155, 70);
      g.drawString("1.)  " + input1 + "     ", 10, 80);
      g.drawString("6.)  " + input6 + "     \n", 300, 80);
      g.drawString("2.)  " + input2 + "     ", 10, 100);
      g.drawString("7.)  " + input7 + "     \n", 300, 100);
      g.drawString("3.)  " + input3 + "     ", 10, 120);
      g.drawString("8.)  " + input8 + "     \n", 300, 120);
      g.drawString("4.)  " + input4 + "     ", 10, 140);
      g.drawString("9.)  " + input9 + "     \n", 300, 140);
      g.drawString("5.)  " + input5 + "     ", 10, 160);
      g.drawString("10.) " + input10 + "    \n", 300, 160);

      String in = JOptionPane.showInputDialog(null,
          "Type \"answers\" to view the answers,\n" +
          "\"exit\" to exit, and \"ignore\" to ignore this message.",
          "Answers",
          JOptionPane.QUESTION_MESSAGE);
      if (in.equals("answers") || in.equals("ANSWERS")) {
        JOptionPane.showMessageDialog(null,
                                      "Answers (Correct Letter)\n\n" +
            "1.)   Cancer cells can mutilate to become resistent to chemo ( T )\n\n" +
            "2.)   Ectoderm gives rise to nerve and skin ( A )\n\n" +
            "3.)   Hair structures are called cilia ( F )\n\n" +
            "4.)   The eyespot detects light ( F )\n\n" +
            "5.)   Cell nucleus is inserted into an cell without a nucleus ( C )\n\n" +
            "6.)   100,000 neurons in brain tissue are about the size of rice ( F )\n\n" +
            "7.)   The PR is at the bottom of the hand bud ( T )\n\n" +
            "8.)   The SRY gene is the key to determining gender ( F )\n\n" +
            "9.)   A,T and G,C are the rules of pairing ( B )\n\n" +
            "10.)  Cells need raw materials to construct new parts ( T )",
            "Answers",
            JOptionPane.WARNING_MESSAGE);
        nothing();
      }
      else if (in.equals("exit") || in.equals("EXIT")) {
        System.exit(0);
      }
      else {
        nothing();
      }
    }
    catch(Exception e2){

    }

  }
}

Can you help me?

Thanks in advanced for your help,
C++

server_crash, that is my website - do u like it?

Yes, looks very nice.

well, i run your program and it crushes on my computer too(wow, its portable....) :)
i think putting these code may cause it, but i am not sure

String in = JOptionPane.showInputDialog(null,
          "Type \"answers\" to view the answers,\n" +
          "\"exit\" to exit, and \"ignore\" to ignore this message.",
          "Answers",
          JOptionPane.QUESTION_MESSAGE);

in your "paint" method, because it not totally inyour hand at when it is going to called. so putting selections it not a good way in paint method, paint method needs to be fast, i think
move it somewhere else :D
and using an array string makes your code shorter....
see ya,

thank u for responding. I don't think having some JOptionPane statements in the paint method is the main problem. I think that ur correct, and it has to do with the JOptionPane u pointed out. I tried making another method - but i get the same result.

More help would be appreciated :( :(

server crash, thanks. the website's for science class (u probably figured that out). My teacher's paying for it ;) Do you have any suggestions

well then, i must insist that it is what causes the bug. every time applet tries to paint itself, it just re-ask you the same question... putting things like JOptionsPane is still not a good idea i think,
but you can create a first time flag, which when you start to program, initilize it to false, then before you display your Joptionpane in paint method check if it is false, if false then display the JOptionPane and make it true... but it is a poor solution.

server crash, thanks. the website's for science class (u probably figured that out). My teacher's paying for it ;) Do you have any suggestions

The only thing I see that needs to be changed, is the JOptionPanes. They pop up when you browse to that page. I think the user should have the choice of taking it, although that is the page for taking it! I believe if you got rid of the JOptionPanes it would look much better.

tonakai, what you helped me with was working perfectly... until now. I get the same error message as before, bad magic number.

My website is: http://www.inquirybio.com/quiz.html

can you help me and also explain what the magic number is?

Thank you SO much in advanced,
C++

if you can send the new source, i can look, but i don't know what is the magic number, may be its something i know but with different name.
how did you produce the bug by the way?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.