Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to put a background image?  RSS feed

 
Sebastian Ossandon
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have to make a Monopoly game and I need to have the image of the board as a background for a JPanel or something.
I found some codes, but I'm having some issues on displaying the rest of the things...
what I wanna do is have a class which is the main frame, and then include in that frame a class which is the board, that extends JPanel... can I do that?
thanks
 
K. Tsang
Bartender
Posts: 3624
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Monopoly?

You can override the JPanel's paintComponent(Graphics) method and provide an Image to the Graphics#drawImage.

Hope this helps.
 
Sebastian Ossandon
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The thing is I don't know how to do that xd, I'm a complete nooob. Can you post an example? I have two classes in two different files and I've tried it but it doesnt work for me.
 
Sebastian Ossandon
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, now the image is on the background and the "JStuff" shows... but I cant place the components where I want.
This is the code:


Monopoly.java




Tablero.java (board)

 
Sebastian Ossandon
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried it but nothing shows
I don't know whats wrong
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ItDoesntWorkIsUseless
Have you compared your code which "doesn't work" to the code demonstrated in the link? Are they the same? Does your new code still have image.paintIcon(this, g, 0, 0); Does the FAQ code have it?

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!