Results 1 to 11 of 11
  1. #1
    Hinadira is offline Member
    Join Date
    Sep 2013
    Posts
    4
    Rep Power
    0

    Angry My applets doesn't work in browsers... like they used to do!

    I wrote short game. It was not ready, but i decided to run it on browser, to check if everything is OK.
    It wasn't. Images didn't appear.
    What was really strange, because on RealJ they appeard.
    I tried to solve problem on my own, got mad and just copied code form here:
    Oracle Image Tutorial

    And the code

    Again, on RealJ everything works fine, on browser images don't even appear.
    I have updated java twice, i used jdk1.7.0_40 and just jdk1.7.0 which i downloaded earlier. Still no images
    In case it was RealJ fault, i compiled it via cmd. The same problem.
    Even... applets compiled earlier doesn't show images!
    Suprisingly, applet on Oracle Image Tutorial works properly.

    Soo... this bug is a real mystery for me. Have any clues?

    Ah... english is not my native language, so please could you write in simpler worlds? I would be very greateful

    EDIT: I forgot to write, that i created 'examples' folder and putted image there

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: My applets doesn't work in browsers... like they used to do!

    I highly doubt this is a bug in Java. It's almost definitely a problem with your understanding.

    Where is your SSCCE? Do you see any errors in the Java console?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: My applets doesn't work in browsers... like they used to do!

    How are you loading the images?
    I'm going to guess that you are not using getResourceAsStream().
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    Hinadira is offline Member
    Join Date
    Sep 2013
    Posts
    4
    Rep Power
    0

    Default Re: My applets doesn't work in browsers... like they used to do!

    WoW! What a fast respond!
    I am now trying to open java console, using tutorial.
    How do I enable and view the Java Console?
    I just can't "Locate Java icon from the System tray on lower right hand side of screen."

    About the code... is in the link up here.
    In case URL doesn't show...
    Webside with tutorial-> Reading/Loading an Image (The Java™ Tutorials > 2D Graphics > Working with Images)
    Java Code:
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.image.*;
    import java.io.*;
    import java.net.URL;
    import javax.imageio.*;
     
    public class LoadImageApplet extends Applet {
     
         private BufferedImage img;
     
         public void init() {
             try {
                 URL url = new URL(getCodeBase(), "examples/strawberry.jpg");
                 img = ImageIO.read(url);
             } catch (IOException e) {
             }
         }
     
         public void paint(Graphics g) {
           g.drawImage(img, 50, 50, null);
         }
    }
    I really hope this is my mistake... java bug would be harder to fix!

    EDIT:
    I got java console working. It is a window with java icon and "Java Console" name, so it might be it.
    It's just displaying:

    Java Plug-in 10.40.2.43
    Using JRE version 1.7.0_40-b43 Java HotSpot(TM) Client VM
    User home directory = C:\Users\Stych

    and help message.

    When i run my applet, nothing happens. Except that it appears
    Last edited by Hinadira; 09-12-2013 at 05:07 PM.

  5. #5
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: My applets doesn't work in browsers... like they used to do!

    When posting code, please use the code tags.

    I see an empty catch block. That's a pretty bad habit, since it hides anything that's going wrong from you.

    Like Tolls said, you need to use getResourceAsStream().
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6
    Hinadira is offline Member
    Join Date
    Sep 2013
    Posts
    4
    Rep Power
    0

    Default Re: My applets doesn't work in browsers... like they used to do!

    I am sorry, because i am just starting with Java. How to use
    Java Code:
    getResourceAsStream()
    in example?

    But thanks for help!

  7. #7
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: My applets doesn't work in browsers... like they used to do!

    What have you googled? I know for a fact there are detailed explanations of that function on this very forum. What have you tried?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #8
    Hinadira is offline Member
    Join Date
    Sep 2013
    Posts
    4
    Rep Power
    0

    Default Re: My applets doesn't work in browsers... like they used to do!

    Yes, i have tried.
    I got this:
    getResourceAsStream : Java Glossary A lot of text which i barely understood! And no examples.
    and this
    How to really read text file from classpath in Java - Stack Overflow but well... this is about main, not applet, which matters... matters?
    and... nevermind.

    Ok, if you don't want to give me an example.
    You really helped me, anyway.
    I need just to figure out how this getResourceAsStream() works.
    Big thanks for fast helping me!

  9. #9
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: My applets doesn't work in browsers... like they used to do!

    This article explained it for me back in the day:

    Smartly load your properties - JavaWorld

    Not for images, but that doesn't matter.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  10. #10
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: My applets doesn't work in browsers... like they used to do!

    See the little search box in the upper-right hand corner? Here are just a few of the first examples I found by typing getResourceAsStream() into it:
    NullPointerException with Java Applet
    Icon not showing up in system tray
    Readinng resources from JAR
    Resouce not found in jar
    What is the cause of this error?
    Creating an executable file - Eclipse
    Importing Sounds
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  11. #11
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: My applets doesn't work in browsers... like they used to do!

    Forum search functions: possible the most overlooked feature of all.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. applets states in browsers
    By laxtrappa in forum Java Applets
    Replies: 5
    Last Post: 03-24-2012, 06:24 PM
  2. Jar doesn't work
    By mad72584 in forum New To Java
    Replies: 35
    Last Post: 08-07-2011, 06:22 PM
  3. No applets work in browser
    By Chotor in forum Java Applets
    Replies: 1
    Last Post: 05-25-2010, 05:19 PM
  4. Why doesn't this work?
    By Corder10 in forum New To Java
    Replies: 1
    Last Post: 07-04-2009, 11:33 PM
  5. Applets painting outside borders in web browsers
    By sirdori in forum New To Java
    Replies: 2
    Last Post: 11-20-2008, 07:14 PM

Tags for this Thread

Posting Permissions

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