Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2006

Tip: Looking for answers? Try searching our database.

Using images in a JApplet

Thread view: 
jay - 07 Jan 2006 06:23 GMT
Hello,
I am having a problem displaying images on an applet, either in a
jlabel or in a jbutton. Every time I run the applet I get an error
message saying "applet not initialized". This is what I am currently
doing to insert a new image in a a JLabel

Image image = null;
           try {
               URL url = new URL(getDocumentBase(),

"http://www.google.com/intl/en/images/logo.gif");
               image = ImageIO.read(url);

           }
           catch (IOException err) {}
//creating label
JLabel label = new JLabel(new ImageIcon(image));

I get the same error from doing this:
JButton button = new JButton(new ImageIcon(

"http://www.google.com/intl/en/images/logo.gif"));

I have tried many different things in the try block but none of them
worked. Does anyone know why this is happening? I am new to using
images on an applet and don't know how to correct this, the only thing
that I could think of is if I loaded the applet in on my site and ran
it from there instead of running it from Eclipse.
Thanks in advance for any help.
Andrew Thompson - 07 Jan 2006 08:35 GMT
> Hello,
> I am having a problem displaying images on an applet,

URL?

>...either in a
> jlabel or in a jbutton.

Are you referring to JLabel/JButton?
Please use correct capitalisation to assist the reader.

>..Every time I run the applet I get an error
> message saying "applet not initialized". This is what I am currently
[quoted text clipped - 5 lines]
>
> "http://www.google.com/intl/en/images/logo.gif");

Is your page at Google?

>                 image = ImageIO.read(url);
>
>             }
>             catch (IOException err) {}

This is rather silly.  Try instead

  catch(IOException ioe) {
    ioe.printStackTrace();
  }

> I have tried many different things in the try block but none of them
> worked.

Try looking at the errors reported in the console.

>.. Does anyone know why this is happening? I am new to using
> images on an applet and don't know how to correct this, the only thing
> that I could think of is if I loaded the applet in on my site

At least on a site other people can see it fail..

Signature

Andrew Thompson
physci, javasaver, 1point1c, lensescapes - athompson.info/andrew

Andrey Kuznetsov - 07 Jan 2006 11:20 GMT
> Image image = null;
>            try {
[quoted text clipped - 5 lines]
>            }
>            catch (IOException err) {}

from Applet you can't connect to other server

Signature

Andrey Kuznetsov
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities

Andrew Thompson - 07 Jan 2006 12:39 GMT
>>Image image = null;
>>           try {
>>               URL url = new URL(getDocumentBase(),
..
> from Applet you can't connect to other server

Sure you can, if the applet is signed and trusted!    ;-)

But then, Google has a habit of 'not permitting access'*
to Java applications and may take similar measures against
Java Applets.

That is why I think console is best.  One step at a time.

* Except of course, through their publicly accessible API.

Signature

Andrew Thompson
physci, javasaver, 1point1c, lensescapes - athompson.info/andrew

Tail_Spin - 08 Jan 2006 00:02 GMT
I just wrote a java ticker applet that goes back to the server it was
downloaded from
and reads a data file that PHP updates on the server from some third party
HTML
files.  And no signing or special security measures!

http://www.freesimracing.com/

So ya, you can connect to the server the applet lives on without much
effort, ... however,
tring to read from somewhere else takes a lot more work.

> > Image image = null;
> >            try {
[quoted text clipped - 13 lines]
> http://reader.imagero.com Java image reader
> http://jgui.imagero.com Java GUI components and utilities
Roedy Green - 07 Jan 2006 19:55 GMT
>"http://www.google.com/intl/en/images/logo.gif");

First of all you need permission from Google to do that.  You could
store the image in you jar.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.