Java Reference
In-Depth Information
public class ItalianFlagComponent extends
JComponent
{
public void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
ItalianFlag flag = new ItalianFlag(100,
100, 90);
flag.draw(g2);
}
}
Step 5 Write the viewer class.
Provide a viewer class, with a main method in which you construct a frame, add
your component, and make your frame visible. The viewer class is completely
routine; you only need to change a single line to show a different component.
import javax.swing.*;
public class ItalianFlagViewer
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.setSize(300, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE
ItalianFlagComponent component = new
ItalianFlagComponent();
frame.add(component);
frame.setVisible(true);
}
}
120
121
R ANDOM F ACT 3.2: Computer Graphics
Generating and manipulating visual images is one of the most exciting applications
of the computer. We distinguish different kinds of graphics.
Diagrams, such as numeric charts or maps, are artifacts that convey information to
the viewer (see Diagrams figure). They do not directly depict anything that occurs
in the natural world, but are a tool for visualizing information.
Search WWH ::




Custom Search