Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I display a bmp on an AWT panel?

Posted on 2001-06-04
5
Medium Priority
?
235 Views
Last Modified: 2013-11-19
How do I display a jpg on an AWT panel?
0
Comment
Question by:hmsjavateam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 28

Expert Comment

by:rrz
ID: 6152733
Use A program such as MS Paint to convert to .gif or .jpg
then Java can accept it.
0
 

Expert Comment

by:JDay
ID: 6153983

You need to tell your program where to find the file.
I think that there are other image objects that you can use besides the icon object. It depends on what you are using.

Icon TrashIcon = new ImageIcon("c:\\TrashIcon.gif");

Then you add the Icon to the panel and set the size and location.

JDay
0
 

Expert Comment

by:SimonSay
ID: 6154963
Which one do you want to display, bmp or jpg?
Java can only display JPG and GIF files. As rrz said, you have to convert your bmp to jpg/gif first.

To display an jpg/gif image, you can do something like this in your public void paint method (assume you are in an applet)

...
Image myimg = getImage(getCodeBase(), "images/mypic.jpg");
...
...
public void paint(Graphics g)
{
   g.drawimage(myimg, x, y, this);
}
//where x, y are the coordinates on the applet

0
 

Author Comment

by:hmsjavateam
ID: 6156961
I need to know how do I display a jpg on an AWT panel running under an application (not an applet), or how to extend applet instead of panel, but load the pannel in an application.
0
 

Accepted Solution

by:
rubenbouman earned 200 total points
ID: 6162706
the comment given by "Simon Say" is for an applet. This code is for an application:

Toolkit tk = Toolkit.getDefaultToolkit();
Image myimg = tk.getImage("c:/images/mypic.jpg");
...
...
public void paint(Graphics g)
{
  g.drawimage(myimg, x, y, this);
}
//where x, y are the coordinates on the panel
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Learn how to create interesting presentations by including videos to keep your audience engaged using Prezi. Select "Insert" from the top menu in your Prezi editor: Select "YouTube Video": Paste the video URL into the prompt: "Select "Insert":…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question