Advanced Search

Page 2 of 2 FirstFirst 12
Results 11 to 20 of 20

Thread: Using Java Applets

  1. #11
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    Sorry, I didn't see your post.
    One of those things.

    We have?
    I'm pretty sure, yes ("I believe..."). If you've posted that link before, then I'm virtually certain.

    Mike

  2. #12
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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!

  3. #13
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    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

  4. #14
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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!

  5. #15
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    No matter how hard I try, I cannot get this to work.

    Here is my Java code:

    Code:
    class HelloWorldApp {
        public static void start(String[] args) {
            System.out.println("Test");
        }
    }
    And the html:

    Code:
    <applet code=HelloWorldApp.class width="200" height="200"></applet>
    ??
    - Mike

  6. #16
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    class HelloWorldApp {
    Quote Originally Posted by myself
    Your applet needs to extend java.awt.Applet or javax.swing.JApplet, depending on your preferred toolkit.
    Code:
        public static void start(String[] args) {
    Quote Originally Posted by myself
    Instead of main(), various event-driven functions such as public void start()
    It's not static, and it doesn't have any arguments.
    Code:
            System.out.println("Test");
    Quote Originally Posted by myself
    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.
    Nice end braces though.
    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!

  7. #17
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    You forgot to type [/code] lol
    - Mike

  8. #18
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    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

  9. #19
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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!

  10. #20
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Nevermind, I got it to work
    - Mike

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •