Ask Questions?

View Latest Questions

Advertisement


 
 

Graphics2D
Posted on: July 26, 2006 at 12:00 AM
The javax.swing.Graphics2D class of Java 2 supports many more graphics operations than the Graphics class.

Java: Graphics2D

The javax.swing.Graphics2D class of Java 2 supports many more graphics operations than the Graphics class. For example,

Graphics2D additional features

  • Aliasing
  • Shapes
  • Affine transformations (scaling, rotation, skewing)
  • [list many others, this is only a rough beginning]

Graphics objects are Graphics2D objects

The Graphics object that is passed to paintComponent is really a Graphice2D object in Java 2, so it may quickly be downcast to Graphics2D to make additional methods available. For example
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D)g;
    // Use g2 for all following operations 
    g2.drawLine(...);
Copyleft 2003 Fred Swartz MIT License, Last update: 2003-10-30
Advertisement


DMCA.com