// be called more than
// perform other initialization (such as registering
a mouse listener) here
public Dimension getPreferredSize()
public void paint(Graphics g)
// perform painting here
It is often not a good idea to override paint() in the context of Swing because
methods: paintComponent() , paintBorder() , and paintChildren() .
allocated to the border.
ize the UI delegate's paint() method should just override paintComponent() .
If you're not concerned about UI delegates, borders, and children, the previous
SwingCanvas class should meet your needs. For more information, check out The
Java Tutorial's “Performing Custom Painting” lesson ( ht-
Java 2D is a collection of AWT extensions that provide advanced two-dimensional
graphical, textual, and imaging capabilities. This API offers a flexible framework for