The JavaTM Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail Search
Examples Index

Trail: Creating a GUI with JFC/Swing

Lesson: Working with Graphics

You might not need to read this lesson at all. Many programs get by with no custom graphics. If they display images, they do so using icons(in the Creating a User Interface trail) in standard Swing components such as labels(in the Creating a User Interface trail) and buttons(in the Creating a User Interface trail). To display styled text, perhaps with embedded images and components, they use text components(in the Creating a User Interface trail). To customize the edges of components, they use borders(in the Creating a User Interface trail).

If you can't find a component that paints what you need onscreen, then read on. This lesson teaches you how to display text, simple shapes, and images, using API that works in both JDK 1.1 and 1.2. Our examples create custom components, but you might also use this API when creating a custom border or icon implementation. This lesson finishes with information about animation.


Note:  If you're using only Java 2 (JDK 1.2, and not JDK 1.1) then in addition to reading the relevant pages in this lesson, you should read the 2D Graphics(in the 2D Graphics trail) trail. That trail describes the JavaTM 2D Graphics API, which provides much more functionality than the graphics primitives described in this lesson.

Overview of Custom Painting

This section gives you the information you need to start implementing custom painting in components.

Using Graphics Primitives

This section teaches you how to paint simple shapes and display text effectively. It includes examples of using the Graphics, Font, and FontMetrics classes.

Using Images

This section discusses how the Java platform supports images and tells you how to load and display images.

Performing Animation

Many programs perform animation, whether it's the classic, cartoon-style animation of Duke waving or simply moving static images across the screen. This section tells you how to perform animation, using a Timer object to implement an animation loop.

Common Graphics Problems (and Their Solutions)

This section describes some common problems of graphics programs, along with possible solutions to these problems.

Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail Search
Examples Index