how to make the Graphics class draw to the GPU in java code example

Example 1: 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.
    .
}

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);
   int width =  getWidth();   // Find out the width of this component.
   int height = getHeight();  // Find out its height.
   . . .   // Draw the content of the component.
}

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

Color randomColor = Color.getHSBColor( (float)Math.random(), 1.0F, 1.0F );

Tags:

Java Example