954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Java applets

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");
}



}





}

krauz2
Light Poster
40 posts since Nov 2006
Reputation Points: 10
Solved Threads: 0
 

1. try using code tags
2. find a book that shows u how to write an applet then experiment?

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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/tutorial/deployment/applet/getStarted.html for the Sun Applet tutorial.

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You