Posted March 28, 200718 yr Hello I just began learning java just a couple days ago, [it is basicly my first language] I seem to have a problem with this tutorial on applets (my applet is broken :tear: ) http://www.mandomartis.com/onlinecourses/basicgamedev/chapter2/chapter2.html It tells me to compile this to a class.... import java.applet.*; import java.awt.*; public class myapplet extends Applet { public void init() { System.out.println("Hello Sweden!"); } } and make an html of this and then open the html <HTML> <HEAD><TITLE>My first applet</TITLE></HEAD> <BODY> <APPLET CODE="myapplet.class" WIDTH=100 HEIGHT=100> </APPLET> </BODY> </HTML> It appears I am getting an error because I do not have a main class but I am not shure, I am doing exactly as the tutorial says is there something I should add. And if it is the main class how and where should I add it. All help is greatly appreciated, Regards, iMi
April 7, 200718 yr public static void main (String args[]) // <-- thats how you make a main { // code here } edit: Or thats how you do it w/ most Java, may be different for an applet
April 23, 200718 yr import java.applet.Applet; public class myapplet extends Applet { public void init() { System.out.println("Hello Sweden!"); } } In an applet, System.out.println() prints to the java console, obviously this is not what you want. In this case we need to draw a string, a picture of a penis, etc, when paint() is called.... import java.applet.Applet; import java.awt.Graphics; public class myapplet extends Applet { public void init() { } public void paint(Graphics g) { g.drawString("Hello Sweden!", 20, 20); } } Now the code in paint() will draw the string "Hello Sweden!" at x:20 and y:20, however, this still not work. You need to set the size of the applet. import java.applet.Applet; import java.awt.Graphics; public class myapplet extends Applet { public void init() { setSize(250, 250); } public void paint(Graphics g) { g.drawString("Hello Sweden!", 20, 20); } } Now it has the ability to draw the string somewhere.