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 / General / November 2006

Tip: Looking for answers? Try searching our database.

How do I put pictures in my Frame?

Thread view: 
Flo - 22 Nov 2006 12:37 GMT
Hey Guys,
very basic question from a beginner..

I need to know how to include a picture in my frame. This script
(http://www.dpunkt.de/java/Programmieren_mit_Java/Applets_und_Applikationen/10.html
/ just look at the script, you don't need to understand what it says)
works perfectly for an Applet, but when I try to use the methods for my
Frame, the compiler always says something like "Cannot Resolve Symbol"
and it points to the g in "getCodeBase(), "

What can I do to use pictures in Frames?

Thanks :).

Flo.
Andrew Thompson - 22 Nov 2006 13:57 GMT
> Hey Guys,
> very basic question from a beginner..

A good group for beginners is comp.lang.java.help.

> I need to know how to include a picture in my frame. This script
> (http://www.dpunkt.de/java/Programmieren_mit_Java/Applets_und_Applikationen/10.html
> / just look at the script, you don't need to understand what it says)

What if it says 'any student found to be seeking
external help will be charged with academic
misconduct'.   ;-)

> ..works perfectly for an Applet, ..

It is extremely unfortunate that most examples of images
and audio clips rely on those idiotic* applet methods.

(* Idiotic in the sense that, they were not really much more
appropriate to 'tag on' to the Applet class, than the
Frame or Window class - if one, it should have been all)

>...but when I try to use the methods for my
> Frame, the compiler always says something like "Cannot Resolve Symbol"
> and it points to the g in "getCodeBase(), "

That means the class you are using, does not have
any such 'getCodeBase()' method.  Check things like
that in the JavaDocs*, for best results.

> What can I do to use pictures in Frames?

Look first to.. (* e.g. of JavaDocs)
<http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Toolkit.html#getImage(java.lang
.String
)>
, then the more useful form that accepts an URL, and their
<http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Toolkit.html#createImage(byte[])>
..variants.

For the replacement to getCodeBase(), you can either..
1) put the image on the project classpath, and call
 Object.getClass().getResource("theImageName")
2) Get a File object pointing to the image and call File.toURL()
..to get an URL.

Note that it is best to have your own copy of the JavaDocs
to browse locally - they can be downloaded.

HTH

Andrew T.


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.