Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I display a bmp on an AWT panel?

Posted on 2001-06-04
5
Medium Priority
?
241 Views
Last Modified: 2013-11-19
How do I display a jpg on an AWT panel?
0
Comment
Question by:hmsjavateam
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

926 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