Printing images – Java Basics #34

Images saved on hard drive or from Internet can be loaded into GUI. We will use Graphics class to do so. Images can be load on many ways. We will use, as far as I’m considered, the simplest one:

image variable contains reference to the filename. We can print it using Graphics class:

drawImage has parameters:


  • image – image to print
  • x – x coordinate
  • y – y coordinate
  • width – image’s width
  • height – image’s height
  • observer – object that allows you to watch visualisation process. Can be null.