Java applets

Reply

Join Date: Nov 2006
Posts: 39
Reputation: krauz2 is an unknown quantity at this point 
Solved Threads: 0
krauz2 krauz2 is offline Offline
Light Poster

Java applets

 
0
  #1
Nov 10th, 2006




Hello everyone,
This is my first java class and I am trying to understand the terms and different types of programs. I finished my program as an application then did it as a gui without realizing it had to be in a applet. It feels like I just learned 2 different languages because the syntax was a little different between them. Now I am trying to figure how to convert this mess into a applet. I am going to mess around with it when I get home from work. Is there any advance help you guys could give to help me start this? I would be very grateful. This is the program that I did in my application and gui. How hard would it be to convert to applet?







import javax.swing.JOptionPane;
import java.util.*;
importstatic java.lang.Math.*;


publicclass program4
{
publicstaticvoid main( String[] args )
{




int number1 = 0;
int number2 = 0;
int actualAnswer = 0;


JOptionPane.showMessageDialog(null, "You will be given math problems to solve.");



number1 = (int)( Math.random () * 9 ); // first variable that will appear in math problem
number2 = (int)( Math.random () * 9 ); // second variable that will appear in math problem
actualAnswer = number1 * number2; // variable that holds true answer to random math problem


String userInput;
double userAnswer = 0.00;
String grade;
String output;
int correctAnswers = 0;
int incorrectAnswers = 0;


userInput = JOptionPane.showInputDialog (null, "Find Product: " + "\n" +
number1 + " Times " + number2);

userAnswer = Double.parseDouble( userInput );




if (userAnswer == actualAnswer) {
JOptionPane.showMessageDialog (null, "You are correct!");
correctAnswers = correctAnswers + 1; // counter to sum total correct answers
JOptionPane.showMessageDialog (null, " You received " + correctAnswers + " Correct answer");

} // if correct, then this is the outcome
else {
JOptionPane.showMessageDialog (null, "You are incorrect! Please try again. ");
incorrectAnswers = incorrectAnswers + 1; // counter to sum total incorrect answers

while (userAnswer != actualAnswer)
{



userInput = JOptionPane.showInputDialog (null, "Find Product: " + "\n" +
number1 + " Times " + number2);
userAnswer = Double.parseDouble( userInput );

if (userAnswer == actualAnswer) {
JOptionPane.showMessageDialog (null, "Great you were able to get the answer!!");
JOptionPane.showMessageDialog (null, " You received " + incorrectAnswers + " incorrect answer");
}



}





}
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Java applets

 
0
  #2
Nov 10th, 2006
1. try using code tags
2. find a book that shows u how to write an applet then experiment?
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,357
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Java applets

 
0
  #3
Nov 11th, 2006
You do really need to look at some Applet tutorials. An applet does not use a main method, a standalone application does. Go to http://java.sun.com/docs/books/tutor...etStarted.html for the Sun Applet tutorial.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC