Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need Help Loading couple images to a BufferedImage.

 
Shika San
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings EveryOne

I am making a board game, I want to load the board and the pieces with their current locations into a BufferedImage then paint the BufferedImage to the screen, is this a good aproch? if not can you show me a better one?

Here is the code that I came up with:



The output is a 50*50 black square, the image doesn't shows up, even it's in the same directory as the applet.

Please SomeOne Help, Thank You.
 
Darryl Burke
Bartender
Posts: 5132
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shika and welcome to the Ranch! First off, please learn to follow coding conventions. Your variable names should start with a lowercase letter.

You have created a BufferedImage of size 50 X 50 pixels. Then you draw another image to its Graphics context, starting at the coordinate [50, 50]. This places the drawn image outside the image it is being drawn to, so it's not surprising that you don't see anything. You need to read the API for the constructors and methods used -- guesswork seldom pays off in programming.

Also note that setSize is not the correct way to size an Applet; that's taken care of in the HTML tag that displays an Applet. and once you get past the basics, you'll likely want to move away from the hugely dated java.awt.Applet to the newer javax.swing.JApplet, when you'll need to learn how custom painting is correctly done in Swing.
 
Darryl Burke
Bartender
Posts: 5132
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, please BeForthrightWhenCrossPostingToOtherSites
http://www.java-forums.org/java-2d/51824-need-help-loading-couple-images-bufferedimage.html
 
Shika San
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You have created a BufferedImage of size 50 X 50 pixels. Then you draw another image to its Graphics context, starting at the coordinate [50, 50]. This places the drawn image outside the image it is being drawn to, so it's not surprising that you don't see anything.


Thank you for your reply.

I have tried what you suggested but the result is the same:



Maybe that's not what you have suggested, but that's what I have understood, Thank You.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic