| | |
Java applets
![]() |
•
•
Join Date: Nov 2006
Posts: 39
Reputation:
Solved Threads: 0
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");
}
}
}
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
----------------------------------------------
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
![]() |
Similar Threads
- Java Applets (Java)
- Java Applets (Java)
- Help-IE6 blocking my java applets (Web Browsers)
- I can't find java applets (Web Browsers)
- java 3d viewable to everyone (Java)
Other Threads in the Java Forum
- Previous Thread: slove my problem
- Next Thread: Customize JFileChooeser
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor crashcourse database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle physics plazmic print problem program programming project recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree trolltech unlimited utility webservices windows






