One of those things.Originally Posted by Twey
I'm pretty sure, yes ("I believe..."). If you've posted that link before, then I'm virtually certain.We have?![]()
Mike
One of those things.Originally Posted by Twey
I'm pretty sure, yes ("I believe..."). If you've posted that link before, then I'm virtually certain.We have?![]()
Mike
I'm fairly positive I haven't, on this forum anyway. Search didn't turn anything up.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
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.
- Mike
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."
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
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>
- Mike
Code:class HelloWorldApp {Originally Posted by myself
Code:public static void start(String[] args) {It's not static, and it doesn't have any arguments.Originally Posted by myself
Code:System.out.println("Test");Nice end braces though.Originally Posted by myself
Code:class HelloWorldApp extends javax.swing.JApplet { public void start() { this.getContentPane().add( new javax.swing.JLabel("Hello, world!") ); } }
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
You forgot to type [/code] lol
- Mike
It still doesn't work....
My Java Console says the following:
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
- Mike
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.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Nevermind, I got it to work![]()
- Mike
Bookmarks