One of those things. :)Quote:
Originally Posted by Twey
I'm pretty sure, yes ("I believe..."). If you've posted that link before, then I'm virtually certain.Quote:
We have? :confused:
Mike
Printable View
One of those things. :)Quote:
Originally Posted by Twey
I'm pretty sure, yes ("I believe..."). If you've posted that link before, then I'm virtually certain.Quote:
We have? :confused:
Mike
I'm fairly positive I haven't, on this forum anyway. Search didn't turn anything up.
Can only certain Java programs work on the web? Because I tried using my "Hello World" program in a web page, but it didn't work.
Applets are constructed differently from applications, and they also have some security barriers in place to prevent harm to the user's computer (these restrictions can be applied to applications as well, but usually aren't).
Your applet needs to extend java.awt.Applet or javax.swing.JApplet, depending on your preferred toolkit. Instead of main(), various event-driven functions such as public void start(), public void init() are used, and obviously the only way to interact with the user is through a GUI (which you can paint onto the Applet or JApplet in the same way you'd use a Panel or JPanel) since there is no console available in the browser.
The default restrictions are mostly obvious things, like not being able to access the filesystem, but there are some less blatant ones as well, such as not being able to call System.exit(). Opening new Frames is allowed, but the frames will have a label somewhere on them saying "Java Applet Window."
No matter how hard I try, I cannot get this to work.
Here is my Java code:
And the html:Code:class HelloWorldApp {
public static void start(String[] args) {
System.out.println("Test");
}
}
??Code:<applet code=HelloWorldApp.class width="200" height="200"></applet>
Quote:
Code:class HelloWorldApp {
Quote:
Originally Posted by myself
Quote:
Code:public static void start(String[] args) {
It's not static, and it doesn't have any arguments.Quote:
Originally Posted by myself
Quote:
Code:System.out.println("Test");
Nice end braces though. :)Quote:
Originally Posted by myself
Code:class HelloWorldApp extends javax.swing.JApplet {
public void start() {
this.getContentPane().add(
new javax.swing.JLabel("Hello, world!")
);
}
}
You forgot to type [/code] lol
It still doesn't work....
My Java Console says the following:
Quote:
load: class panorama.class not found.
java.lang.ClassNotFoundException: panorama.class
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadCode(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: C:\java\java\panorama\class.class (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.http://www.protocol.file.FileURLConn...onnect(Unknown Source)
at sun.net.http://www.protocol.file.FileURLConn...Stream(Unknown Source)
at sun.applet.AppletClassLoader.getBytes(Unknown Source)
at sun.applet.AppletClassLoader.access$100(Unknown Source)
at sun.applet.AppletClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 10 more
That's because you've copied the code directly from the example to which I linked, without modifying it for your applet. In fact, you should be using Mike's, which is, as he says, better.
For testing purposes only, though, your <applet> tag should do fine.
Nevermind, I got it to work :)