java graphics drawer tool code example

Example 1: Write a simple java swing application that will display rectangle graphics as shown in the picture below:

public void paintComponent(g) {
   super.paintComponent(g);
   . . . // Draw the content of the component.
}

Example 2: Write a simple java swing application that will display rectangle graphics as shown in the picture below:

public void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D g2;
   g2 = (Graphics2D)g;
    .
    . // Draw on the component using g2.
    .
}

Tags:

Java Example