PDA

View Full Version : Java App Will Not Execute.


GSimpson
09-20-2006, 11:47 AM
MyProgram.java

public class MyProgram {

public static void main(String[] args) {
System.out.println(
"Eureka, I can put Java on my resume.");
}
}


I then used 'javac' to convert that into a file named 'MyProgram.class'.

I have an html that looks like this:

<html>
<head>
<title></title>
</head>
<body>
<applet width="300" height="300" src="MyProgram.class"></applet>
</body>
</html>


Now I am quite new to java and i'm not sure but I think my software is ok so if i can get an explanation to why this only displays a little white piece of paper with a red 'X'. Thanks so much in advance, GSimpson.

Phill
09-20-2006, 12:01 PM
You need to read a good end-to-end tutorial on Java and specifically, applets (if you want your java program to display in a web browser).

Seriously, there's way too much to go into in a couple of paragraphs! :D

GSimpson
09-20-2006, 10:48 PM
OK, but in the tutorial that I'm reading that's exactly what it says to do.

Gox
09-21-2006, 12:32 AM
Have a look at Java's own Applet turtorial, http://java.sun.com/docs/books/tutorial/deployment/applet/index.html

Code snippets you'll want to look at:

<applet code=HelloWorld.class width="200" height="200"></applet>



import javax.swing.JApplet;
import java.awt.Graphics;

public class HelloWorld extends JApplet {
public void paint(Graphics g) {
g.drawRect(0, 0,
getSize().width - 1,
getSize().height - 1);
g.drawString("Hello world!", 5, 15);
}
}


Also Java's API is invaluable. Familiarize yourself with it and it will help you solve many problems very quickly. http://java.sun.com/j2se/1.3/docs/api/

Java tutorial site: http://java.sun.com/docs/books/tutorial/index.html

Usually when I need to find something Java related I head to google, seach: Java api 'whatever' and will find a related document in the api files.
Example: for this thread a googled: Java api Applet and that tutorial was the first link.

GSimpson
09-21-2006, 04:44 AM
Ok thanks phill i'm sure my java will be better from here on