PDA

View Full Version : Beginner help with using APPLET


Shai_Hulud
01-15-2009, 11:32 PM
First post! I'm pretty excited to be getting into a forum that doesn't RickRoll me every 5 seconds. :thumbsup:

I'm taking intro to JAVA, and we are discussing the use of APPLET. He posted this code on our class website, and its not pulling up in my compiler. Is there something wrong with the code itself?

I apologize if this is a n00bie b00bie post, but you gotta start somewhere right?
import java.applet.*;
import javax.swing.JOptionPane;
import java.awt.*;

public class AppletTest extends Applet
{
public void init(){
System.out.println("Applet initialization.");
}

public void start(){
System.out.println("Applet starting.");
}

/**
* public void stop(){
System.out.println("Applet stopping.");
}
**/



public void paint(Graphics g) {
g.drawString("Hello ", 5, 15);
String name = JOptionPane.showInputDialog("What is your name?");
g.drawString("Hello " + name + ". Welcome to GGC!", 5, 15);
}
}


I understand that essentially is supposed to log what you type in as your name and display simple text output including your name in the text.

But why the use of an applet? I can't investigate this myself b/c my compiler states:

"Static Error: No method in AppletTest with name 'main' accepts arguments (String[])"

when ever i attempt to run the code. Any sort of feedback on this would be so helpful. Thank you.

brad211987
01-16-2009, 02:14 PM
Been quite a while since I've even looked at an applet, but my guess is you are trying to simply execute the applet program using the java command, or the function of an editor. Applets cannot be run this way as far as I know. You will need to look into either embedding it into a mockup web page or using the applet viewer.

A google search for the applet viewer turned up: http://www.kevinboone.com/howto_appletviewer.html

That should get you going in the right direction.

servlet
01-21-2009, 05:38 AM
Applets don't need main(String args[]) method at all, they can't run as stand alone java program.
You must embed it into an HTML page or use Applet viewer to execute it.

Look at http://java.sun.com/j2se/1.3/docs/tooldocs/win32/appletviewer.html

--------------
SN Java Servlets (http://www.jsptube.com)