Graphics Reference
In-Depth Information
established standard libraries, users can use them without any future compatibility
problems.
Because of its OOP design, it is easy in Java to use other nonstandard libraries
writtenbymanyauthors.hereareseveralreliablelibrariesthatareessential forasta-
tistical graphics library, such as a library for data import and export using the Excel
format (Jakarta POI), and a library for outputting graphics using the SVG format
(Batik SVG Toolkit).
Design Patterns
OOPisane cientprogrammingparadigmforachievingextensibilityandreusability
of programs. Recently, several approaches to writing good object-oriented programs
have been proposed as “design patterns.” Design patterns describe how objects com-
municate without being entangled in each other's data and code.
Java developers use them extensively, and many standard libraries have been de-
velopedbyfollowingthem.WhenweuseJavastandardlibraries,wecanseeandlearn
what design patterns advocate.
Basics of Java Graphics
17.2.3
Recent Java graphics programming mainly uses the Java D and Swing libraries. We
note that Java libraries are documented by the Java Application Programming In-
terface (API). API is a list of Java packages, classes, and interfaces with all of their
methods, fields and constructors, and also with information on how to use them.
hefirstAPIforgraphics programmingwastheAbstractWindowToolkit (AWT).
Java D API provides the Graphics2D class (a subclass of the Graphics class in
AWT), which contains a much richer set of drawing operations.
Swing is a package that provides a set of lightweight and enhanced components
that replacethe onesavailable fromAWT.For example, the JButton classenhances
the Button class in AWT in order to allow not just text but images too on a button.
Java Dand Swing are included in Java Foundation Classes (JFC), which is a set of
APIs intended to be a supplement to AWT. he Accessibility API and the Drag and
Drop API are also included in JFC.
An Example of Java Graphics Programming
As an example of using Java D and Swing API, we now list a short program that
draws line segments and points in a window on the screen.
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Graphics;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import javax.swing.JFrame;
public class GraphicExample extends JFrame {
public static void main(String[] args){
GraphicExample ge = new GraphicExample();
ge.setDefaultCloseOperation(EXIT_ON_CLOSE);
Search WWH ::




Custom Search