• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help displaying images.

 
Alex Hayes
Greenhorn
Posts: 7
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could some one please explain why this code, doesn't display the image?


I have tried looking things up, but nothing seems to work.
 
Piet Souris
Rancher
Posts: 1641
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Alex,

it is because you must do the painting of your image inside
a JPanel.

If you look at your 'main' method, you see that you create a JFrame,
and that is pretty much all. Your image is never drawn here.

You must create a JPanel, in which you override the 'paintComponent'
method such that you draw your image in this overridden method.
Add this JPanel to your frame. Pay attention, in that case, in what part
of your class you load the image.

Give it a try, and let us know if you encounter any problem.

Greetz,
Piet
 
Darryl Burke
Bartender
Posts: 5155
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alex Hayes wrote:f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});[/code]

That resembles archaic AWT code. In Swing, you should set the default close operation of the JFrame.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!