Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

No progress...help  RSS feed

 
shane ocon
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please could any one help me...i know there are previous posts on this topic but i cannot understand what is going on in any of them as im a total beginner...
I want to display an image as the background on a jpanel...
Could anyone give me an example of the easiest and simplest code for this..

tanx in advanz
 
Paul Clapham
Sheriff
Posts: 22487
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you put "display an image as the background on a jpanel" into your favourite search engine, you will easily get a few examples of how to do that.

But you say you have already seen such things (or is that what you said?) and you don't understand them. Fair enough, that's normal for beginners. So what you have to do is work at learning the background until you do understand them. Asking for the code isn't going to help, you have probably already seen the code.
 
shane ocon
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks for replying your prob right...

i found the code as below...is this image coming from a url on the net???
i want it to come from a folder...
class BackgroundPanel extends JPanel
{
Image image;
public BackgroundPanel()
{
try
{
image = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("Test.gif"), "Test.gif"));
}
catch(Exception e){/*handled in paintComponent()*/}
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
if(image != null) g.drawImage(image, 0,0,this.getWidth(),this.getHeight(),this);
}
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!