Retrieving and Using Images

Basic image handling in Java is conducted through the Image class, which is part of the java.awt package. Image objects can represent graphics in three file formats: GIF, JPEG, and PNG.

You cannot create Image objects directly. Applets have several methods for loading image files using its filename or a URL, an address indicating where the graphics file is available on the Internet. Applications can use class methods of the Toolkit class, part of the java.awt package, to work with images.

After you have an Image object, you can display it in a component using methods of the Graphics or Graphics2D classes.

Getting Images

To associate a graphics file with an Image object in an application, you can call the createImage() ...

Get Sams Teach Yourself Java 2 in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.