Alright, this is a school assignment. Unfortunately, we were given about a paragraph of info on apps so I'm not sure what I'm doing wrong. I know it's a pretty random app, but these are the elements that she wanted.
My problem is that it runs infinitely when I run the program and when I view it as an html. Help me!
import java.applet.Applet;
import java.awt.Graphics;
import javax.swing.JOptionPane;
/**
* The HelloWorld class implements an applet that
* simply displays "Hello World!".
*/
public class HelloWorld extends Applet {
public void paint(Graphics g) {
g.drawString("Hello World Applet", 50, 25);
g.drawString("Author: Joshua Cimbron", 50, 10);
String input1 = JOptionPane.showInputDialog("Please enter a value");
double a = Double.parseDouble(input1);
String input2 = JOptionPane.showInputDialog("Please enter another value");
double b = Double.parseDouble(input2);
String input3 = JOptionPane.showInputDialog("Please enter a final value");
double c = Double.parseDouble(input3);
g.drawString(("The average is: " + average(a, b, c)), 50, 100);
System.out.println ("Hi! This is a test! What's println do in an applet? :)");
}
public static double average (double a, double b, double c) {
double sum = a + b + c;
double average = sum / 3;
return average;
}
}
// html file
// file:///C:/Users/Josh/Documents/NetBeansProjects/HelloWorldApplet/build/HelloWorld.html