Table of Contents

Java: User Interface Components and 2D Graphics


User Interface and Interactive Components

The Java Approach

The JFrame Container

The JPanel Container

Swing User Interface Components

Event Handling

Handling Mouse Clicking Events

Handling Keyboard Events


2D Graphics

Vector vs. Raster Graphics

vector.jpg ataris-1983-star-wars-arcade-game-featured-simple-vector-graphics-but-at-the-time-the-experience-was-mind-blowing_o-z-94211-13.jpg

retrogames_raster.jpg

2D Rendering Primitives

Coordinate System


2D Graphics in Java

The Java 2D paintComponent() Method in a JPanel

      public void paintComponent (Graphics g)
      {
        Graphics2D g2 = (Graphics2D)g;
        // This is where you will do your work
        ...
        ...
      }

Old Graphics Primitive Methods (That Still Work)

Colors

Class Diagram for (some of) Java's graphics routines

Graphics2D Primitive Methods

Manipulations and Transformations

Moving Pictures

Drawing Images (external images, e.g. gif, png, jpg)


Code Samples