Painting in swing
Painting is used, when we want to change or enhance an existing widget.
Or if we are creating a custom widget from scratch. To do the painting, we use
the painting API provided by the Swing toolkit.
The painting is done within the paintComponent() method. In the painting
process, we use the Graphics2D object.
2D Vector
Graphics
There are two different computer graphics.
·
Vector graphics
·
raster graphics
Raster graphics represents images as a collection of pixels. Vector
graphics is the use of geometrical primitives such as points, lines, curves or
polygons to represent images. These primitives are created using mathematical
equations.
Both types of computer graphics have advantages and disadvantages. The
advantages of vector graphics over raster are:
- smaller size
- ability to zoom indefinitely
- moving, scaling, filling or rotating does not degrade the quality of an image
Types of primitives
- points
- lines
- polylines
- polygons
- circles
- ellipses
- Splines
Points
The most simple graphics primitive is point. It is a single dot on the
window. There is no method to draw a point in Swing. To draw a point, we use
the drawLine() method. We use one point twice.
Comments
Post a Comment