A fundamental three-step recipe exists for programming graphics in Java. Get (or modify) the Graphics2D context, create some geometry (or an image), and call a rendering method. The following short code snippet demonstrates this recipe:
public void paint(Graphics g) { //get instance of graphics context Graphics2D g2d = (Graphics2D) g; //modify the graphics context g2d.setColor(Color.blue); //call a render method g2d.fill(new Ellipse2D.Float(5.f,5.f, 40.f, 40.f,); }
Several complete examples are developed in Chapter 3, “Graphics Programming with the Java 2D API.”