This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
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.
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.
There are no new questions, but there may be new answers.
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.