Applet program

When you do an applet program you need to have also main?
[64 byte] By [Maria81a] at [2007-11-27 1:49:41]
# 1
No.Check out the section of Sun's Tutorial that deals with Applets: http://java.sun.com/docs/books/tutorial/deployment/applet/getStarted.html There's a minimal example of an Applet on at the start of that page. Note how there is no main() method.
pbrockway2a at 2007-7-12 1:15:19 > top of Java-index,Java Essentials,New To Java...
# 2

I already have the program but when I run it gives me an error

"java.lang.NoSuchMethodError: main

Exception in thread "main"

Process completed."

So maybe I have something wrong.

This is my code

import javax.swing.JApplet;

import java.awt.Graphics;

import javax.swing.JOptionPane;

public class ThreeNumbers extends JApplet

{

double sum;

public void init()

{

String firstNum,

secondNum;

double number1,

number2;

firstNum = JOptionPane.showInputDialog("Enter the first floating point value: ");

number1 = Double.parseDouble(firstNum);

secondNum = JOptionPane.showInputDialog("Enter the second floating point value: ");

number2 = Double.parseDouble(secondNum);

sum = number1 + number2;

}

public void paint (Graphics g)

{

super.paint(g);

g.drawRect(15, 10, 270, 20);

g.drawString("The sum is " +sum, 25, 25);

}

}

Maria81a at 2007-7-12 1:15:19 > top of Java-index,Java Essentials,New To Java...
# 3
Create an html file to display the Applet.
CaptainMorgan08a at 2007-7-12 1:15:19 > top of Java-index,Java Essentials,New To Java...
# 4

"Process completed" sounds like you are using some sort of IDE. In that case you should check out whatever tutorials and other documentation came with it.

As far as Java is concerned the Tutorial I linked to before talks about how to run (deploy) applets. The section "Using the Applet Tag" (http://java.sun.com/docs/books/tutorial/deployment/applet/applettag.html) will prove especially useful. Note that applets exist within web pages, so you write a small web page and use the <APPLET> tag. "Running" the applet consists of displaying the web page in you web browser.

If you want to avoid writing a web page, there is the java tool appletviewer. It is described here: http://java.sun.com/javase/6/docs/technotes/tools/windows/appletviewer.html

pbrockway2a at 2007-7-12 1:15:19 > top of Java-index,Java Essentials,New To Java...
# 5

I did it too, but when I run it gives an error message

class, interface, or enum expected

Here it is

<html>

<applet code="ThreeNumbers.class" width="300" height="65">

</applet>

</html>

Maria81a at 2007-7-12 1:15:19 > top of Java-index,Java Essentials,New To Java...