PDA

View Full Version : Help(cant get applet to load)


HQcool22
08-23-2007, 07:00 AM
I am using this,

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> Your Title Here </title>

</head>

<body>
<APPLET CODE="test.java" WIDTH="400" HEIGHT="200">
</APPLET>

</body>
</html>

But the file i made does not work. all i get is a nice big gray screen with a big red "x" in the top corner. If somebody could actually explain how the applets work to me that would help me even more so i can start learning again...

thanks for any help,
,
,
,

amitthechosen1
08-23-2007, 11:12 AM
Hi,
Can you post the code inside test.java.

Regards
amit

amitthechosen1
08-23-2007, 01:46 PM
Hi,
I can easily spot the error from the code you have pasted.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> Your Title Here </title>

</head>

<body>
<APPLET CODE="test.java" WIDTH="400" HEIGHT="200">
</APPLET>

</body>
</html>

This should have been test.class, since we have to specify the name of the class file here.
.
I am explaining you some simple steps for compiling an applet :-
1) my hello.java

import java.awt.* ;
import java.applet.*;

public class hello extends Applet {

public void paint(Graphics g) {
g.drawString("Welcome to the world of Applets",50,10);
g.setColor(Color.gray);
}

}

2) Generate the .class file by compiling this .java file :-
--> javac hello.java
3) Open the notepad and type the below code :-
<html>
<applet code="hello.class" width="300" height="300" > </applet>

</html>
--> save this as hello.html, and close it.
4. On the command prompt, type the following :-

--> appletviewer hello.html

The applet will appear without any error.

5.) Modify the java file to gain isight for various other features supported.

Regards
Amit.

HQcool22
08-24-2007, 11:34 PM
How do i compile it?

brad211987
08-25-2007, 02:24 PM
You can compile any .java file by navigating to its directory on the command line and typing: javac myJavaFile.java

of course, replacing "myJavaFile" with the name of your file.

amitthechosen1
08-25-2007, 04:30 PM
This is explained in the post.

Also, for learning java, try not to use IDE(Integrated Development Environment ) during the learning stage. This hampers the conceptual part.

Use notepad and compile in the command prompt.
If you need help on that too, then i suppose you need to do some google search for basic java.

The above method is right, and your applet must also work fine.

Regards
Amit
:thumbsup:

Aradon
08-25-2007, 09:30 PM
You can compile any .java file by navigating to its directory on the command line and typing: javac myJavaFile.java

of course, replacing "myJavaFile" with the name of your file.

I just want to add that depending on the envorinment you are compiling on (windows, linux, etc) will depend if javac is in your path variables.

If this doesn't work (just typing javac) then you need to add it to your path. In windows this can be achieved by right clicking on my computer, going to properties, clicking on the advanced tab, then clicking on environment variables, clicking on the Path variable in system variables, clicking edit, then adding at the end the bin folder where javac is located (typically in standard installations in windows it's in C:\Program Files\java\jdk_version\bin )