944,134 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 5352
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Mar 30th, 2005
0

Java Applet Help

Expand Post »
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++
Similar Threads
Reputation Points: 12
Solved Threads: 2
Posting Whiz
Ghost is offline Offline
352 posts
since Aug 2004
Mar 30th, 2005
0

Re: Java Applet Help

this is the buggy line
<applet code = "http://www.inquiryBio.com/quiz.class/" width = "400" height = "180">
you need to remove the last slash
Java Syntax (Toggle Plain Text)
  1. <applet code = "http://www.inquiryBio.com/quiz.class" width = "400" height = "180">
Reputation Points: 25
Solved Threads: 11
Junior Poster
tonakai is offline Offline
121 posts
since Feb 2005
Mar 30th, 2005
0

Re: Java Applet Help

Is that your website?
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Mar 30th, 2005
0

Re: Java Applet Help

tonakai, THANK YOU!!!

server_crash, that is my website - do u like it?
Reputation Points: 12
Solved Threads: 2
Posting Whiz
Ghost is offline Offline
352 posts
since Aug 2004
Mar 30th, 2005
0

Re: Java Applet Help

srry 2 double post, but:

tonakai, it worked but the applet freezes on the last JOptionPane screen. Here's my code:
Java Syntax (Toggle Plain Text)
  1. import java.awt.Graphics;
  2. import javax.swing.*;
  3. import java.awt.*;
  4.  
  5. public class quiz extends JApplet
  6. {
  7. double t;
  8. int corCount;
  9. String input1;
  10. String input2;
  11. String input3;
  12. String input4;
  13. String input5;
  14. String input6;
  15. String input7;
  16. String input8;
  17. String input9;
  18. String input10;
  19.  
  20.  
  21. public void init(){
  22.  
  23. try{
  24. JOptionPane.showMessageDialog(null,
  25. "Welcome to the quiz.\n\n" +
  26. "For multiple choice questions, enter the best LETTER.\n" +
  27. "For true / false quetions, enter 'T' or 'F'.\n\n" +
  28. "This quiz consists of 10 questions.",
  29. "R E A D T H I S M E S S A G E !",
  30. JOptionPane.WARNING_MESSAGE);
  31.  
  32. input1 = JOptionPane.showInputDialog(null,
  33. "True or False:\n" +
  34. "Cancer cells can mutilate and become resistent to\n" +
  35. "chemotherapy drugs.\n", "TRUE OR FALSE ('T' or 'F')",
  36. JOptionPane.INFORMATION_MESSAGE);
  37.  
  38. if (input1.equals("T") || input1.equals("t")) {
  39. corCount++;
  40. }
  41.  
  42. input2 = JOptionPane.showInputDialog(null,
  43. "Multiple Choice:\n" +
  44. "Ectoderm gives rise to which of the following:\n\n" +
  45. "A nerve+skin\n" +
  46. "B internal organs\n" +
  47. "C muscles and bone\n" +
  48. "D all of the above\n",
  49. "Multiple Choice",
  50. JOptionPane.INFORMATION_MESSAGE);
  51.  
  52. if (input2.equals("A") || input2.equals("a")) {
  53. corCount++;
  54. }
  55.  
  56. input3 = JOptionPane.showInputDialog(null,
  57. "True or False:\n" +
  58. "The hair-like structures covering the\n" +
  59. "paramicium are flagella.\n", "TRUE OR FALSE ('T' or 'F')",
  60. JOptionPane.INFORMATION_MESSAGE);
  61.  
  62. if (input3.equals("F") || input3.equals("f")) {
  63. corCount++;
  64. }
  65.  
  66. input4 = JOptionPane.showInputDialog(null,
  67. "True or False:\n" +
  68. "The chloroplast detects light in a euglena.\n"
  69. , "TRUE OR FALSE ('T' or 'F')",
  70. JOptionPane.INFORMATION_MESSAGE);
  71.  
  72. if (input4.equals("F") || input4.equals("f")) {
  73. corCount++;
  74. }
  75.  
  76. input5 = JOptionPane.showInputDialog(null,
  77. "Multiple Choice:\n" +
  78. "While cloning, a specialized cell nucleus is inserted into:\n\n" +
  79. "A another specialized cell\n" +
  80. "B a normal egg\n" +
  81. "C an egg that had its nucleus removed\n" +
  82. "D the uterus of a female\n",
  83. "Multiple Choice",
  84. JOptionPane.INFORMATION_MESSAGE);
  85.  
  86. if (input5.equals("C") || input5.equals("c")) {
  87. corCount++;
  88. }
  89.  
  90. input6 = JOptionPane.showInputDialog(null,
  91. "True or False:\n" +
  92. "100,000,000,000 neurons are in a piece of tissue the size of a grain of rice.\n"
  93. , "TRUE OR FALSE ('T' or 'F')",
  94. JOptionPane.INFORMATION_MESSAGE);
  95.  
  96. if (input6.equals("F") || input6.equals("f")) {
  97. corCount++;
  98. }
  99.  
  100. input7 = JOptionPane.showInputDialog(null,
  101. "True or False:\n" +
  102. "The PR is in the bottom of the bud of the hand.\n"
  103. , "TRUE OR FALSE ('T' or 'F')",
  104. JOptionPane.INFORMATION_MESSAGE);
  105.  
  106. if (input7.equals("T") || input7.equals("t")) {
  107. corCount++;
  108. }
  109.  
  110. input8 = JOptionPane.showInputDialog(null,
  111. "True or False:\n" +
  112. "The SRC gene is the key to determining gender.\n"
  113. , "TRUE OR FALSE ('T' or 'F')",
  114. JOptionPane.INFORMATION_MESSAGE);
  115.  
  116. if (input8.equals("F") || input8.equals("f")) {
  117. corCount++;
  118. }
  119.  
  120. input9 = JOptionPane.showInputDialog(null,
  121. "True or False:\n" +
  122. "Select the gene rules of pairing.\n\n" +
  123. "A T,C and A,G\n" +
  124. "B A,T and G,C\n" +
  125. "C T,G and A,C\n" +
  126. "D both b and c\n"
  127. , "TRUE OR FALSE ('T' or 'F')",
  128. JOptionPane.INFORMATION_MESSAGE);
  129.  
  130. if (input9.equals("B") || input9.equals("b")) {
  131. corCount++;
  132. }
  133.  
  134. input10 = JOptionPane.showInputDialog(null,
  135. "True or False:\n" +
  136. "Cells need glucose to construct new parts.\n"
  137. , "TRUE OR FALSE ('T' or 'F')",
  138. JOptionPane.INFORMATION_MESSAGE);
  139.  
  140. if (input10.equals("T") || input10.equals("t")) {
  141. corCount++;
  142. }
  143.  
  144. if (corCount >= 8) {
  145. JOptionPane.showMessageDialog(null,
  146. "\nNumber Correct: " + corCount + " / 10",
  147. "Congratulations!!!",
  148. JOptionPane.INFORMATION_MESSAGE);
  149. }
  150. else if (corCount >= 5) {
  151. JOptionPane.showMessageDialog(null,
  152. "\nNumber Correct: " + corCount + " / 10",
  153. "Better Luck Next Time...",
  154. JOptionPane.INFORMATION_MESSAGE);
  155. }
  156. else {
  157. JOptionPane.showMessageDialog(null,
  158. "\nNumber Correct: " + corCount + " / 10",
  159. "Go Back to Preschool",
  160. JOptionPane.INFORMATION_MESSAGE);
  161. }
  162. }
  163. catch(Exception e){
  164.  
  165. }
  166.  
  167. }
  168.  
  169. public void nothing(){
  170. try{
  171. //this method halts the program - does nothing, hence the name nothing
  172. }
  173. catch(Exception e3){
  174.  
  175. }
  176. }
  177.  
  178. public void paint(Graphics g)
  179. {
  180. super.paint(g);
  181. try{
  182.  
  183. g.setFont(new Font("arial", Font.BOLD, 16));
  184.  
  185. g.drawString(" Q U I Z ! ! ! ", 115, 15);
  186. g.drawRoundRect(45, 30, 270, 20, 15, 15);
  187.  
  188. g.setFont(new Font("arial", Font.BOLD + Font.ITALIC, 14));
  189.  
  190. g.drawString("Questions Correct: " + corCount + " out of 10", 50, 45);
  191.  
  192. g.setFont(new Font("arial", Font.PLAIN, 12));
  193.  
  194. g.drawString("Your Input:", 155, 70);
  195. g.drawString("1.) " + input1 + " ", 10, 80);
  196. g.drawString("6.) " + input6 + " \n", 300, 80);
  197. g.drawString("2.) " + input2 + " ", 10, 100);
  198. g.drawString("7.) " + input7 + " \n", 300, 100);
  199. g.drawString("3.) " + input3 + " ", 10, 120);
  200. g.drawString("8.) " + input8 + " \n", 300, 120);
  201. g.drawString("4.) " + input4 + " ", 10, 140);
  202. g.drawString("9.) " + input9 + " \n", 300, 140);
  203. g.drawString("5.) " + input5 + " ", 10, 160);
  204. g.drawString("10.) " + input10 + " \n", 300, 160);
  205.  
  206. String in = JOptionPane.showInputDialog(null,
  207. "Type \"answers\" to view the answers,\n" +
  208. "\"exit\" to exit, and \"ignore\" to ignore this message.",
  209. "Answers",
  210. JOptionPane.QUESTION_MESSAGE);
  211. if (in.equals("answers") || in.equals("ANSWERS")) {
  212. JOptionPane.showMessageDialog(null,
  213. "Answers (Correct Letter)\n\n" +
  214. "1.) Cancer cells can mutilate to become resistent to chemo ( T )\n\n" +
  215. "2.) Ectoderm gives rise to nerve and skin ( A )\n\n" +
  216. "3.) Hair structures are called cilia ( F )\n\n" +
  217. "4.) The eyespot detects light ( F )\n\n" +
  218. "5.) Cell nucleus is inserted into an cell without a nucleus ( C )\n\n" +
  219. "6.) 100,000 neurons in brain tissue are about the size of rice ( F )\n\n" +
  220. "7.) The PR is at the bottom of the hand bud ( T )\n\n" +
  221. "8.) The SRY gene is the key to determining gender ( F )\n\n" +
  222. "9.) A,T and G,C are the rules of pairing ( B )\n\n" +
  223. "10.) Cells need raw materials to construct new parts ( T )",
  224. "Answers",
  225. JOptionPane.WARNING_MESSAGE);
  226. nothing();
  227. }
  228. else if (in.equals("exit") || in.equals("EXIT")) {
  229. System.exit(0);
  230. }
  231. else {
  232. nothing();
  233. }
  234. }
  235. catch(Exception e2){
  236.  
  237. }
  238.  
  239. }
  240. }

Can you help me?

Thanks in advanced for your help,
C++
Reputation Points: 12
Solved Threads: 2
Posting Whiz
Ghost is offline Offline
352 posts
since Aug 2004
Mar 30th, 2005
0

Re: Java Applet Help

Quote originally posted by C++ ...
server_crash, that is my website - do u like it?
Yes, looks very nice.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Mar 31st, 2005
0

Re: Java Applet Help

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
Java Syntax (Toggle Plain Text)
  1. String in = JOptionPane.showInputDialog(null,
  2. "Type \"answers\" to view the answers,\n" +
  3. "\"exit\" to exit, and \"ignore\" to ignore this message.",
  4. "Answers",
  5. 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
and using an array string makes your code shorter....
see ya,
Reputation Points: 25
Solved Threads: 11
Junior Poster
tonakai is offline Offline
121 posts
since Feb 2005
Mar 31st, 2005
0

Re: Java Applet Help

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
Reputation Points: 12
Solved Threads: 2
Posting Whiz
Ghost is offline Offline
352 posts
since Aug 2004
Mar 31st, 2005
0

Re: Java Applet Help

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.
Reputation Points: 25
Solved Threads: 11
Junior Poster
tonakai is offline Offline
121 posts
since Feb 2005
Mar 31st, 2005
0

Re: Java Applet Help

Quote originally posted by C++ ...
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.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: How DO you count Upper Case letters?
Next Thread in Java Forum Timeline: Best Java Program Editor?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC