• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Need Help Loading couple images to a BufferedImage.

 
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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • 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: 5167
11
Netbeans IDE Opera Java
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!