Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto the screen.

Class JPanel (from package javax.swing) provides an area on which we can draw.

Click here for the codes.

The keyword extends creates a so-called inheritance relationship.

JPanel has a paintComponent method, which the system calls every time it needs to display the JPanel.

super.paintComponent( g );

To display the DrawPanel on the screen, place it in a window.

More topics:

a. Empty Frame
b. Rectangle Component
c. Rectangle Applet
d. Ellipse Component
e. Line Segment
f. Draw a Face