Java Reference
In-Depth Information
f) Graphics is an abstract class.
g) The Font class inherits directly from class Graphics .
13.6 (Concentric Circles Using Method drawArc ) Write an application that draws a series of eight
concentric circles. The circles should be separated by 10 pixels. Use Graphics method drawArc .
13.7 (Concentric Circles Using Class Ellipse2D.Double ) Modify your solution to Exercise 13.6
to draw the ovals by using class Ellipse2D.Double and method draw of class Graphics2D .
13.8 (Random Lines Using Class Line2D.Double ) Modify your solution to Exercise 13.7 to
draw random lines in random colors and random thicknesses. Use class Line2D.Double and method
draw of class Graphics2D to draw the lines.
13.9 (Random Triangles) Write an application that displays randomly generated triangles in dif-
ferent colors. Each triangle should be filled with a different color. Use class GeneralPath and meth-
od fill of class Graphics2D to draw the triangles.
13.10 (Random Characters) Write an application that randomly draws characters in different
fonts, sizes and colors.
13.11 (Grid Using Method drawLine ) Write an application that draws an 8-by-8 grid. Use
Graphics method drawLine .
13.12 (Grid Using Class Line2D.Double ) Modify your solution to Exercise 13.11 to draw the
grid using instances of class Line2D.Double and method draw of class Graphics2D .
13.13 (Grid Using Method drawRect ) Write an application that draws a 10-by-10 grid. Use the
Graphics method drawRect .
13.14 (Grid Using Class Rectangle2D.Double ) Modify your solution to Exercise 13.13 to draw
the grid by using class Rectangle2D.Double and method draw of class Graphics2D .
13.15 (Drawing Tetrahedrons) Write an application that draws a tetrahedron (a three-dimension-
al shape with four triangular faces). Use class GeneralPath and method draw of class Graphics2D .
13.16 (Drawing Cubes) Write an application that draws a cube. Use class GeneralPath and meth-
od draw of class Graphics2D .
13.17 (Circles Using Class Ellipse2D.Double ) Write an application that asks the user to input
the radius of a circle as a floating-point number and draws the circle, as well as the values of the
circle's diameter, circumference and area. Use the value 3.14159 for
π
. [ Note: You may also use the
predefined constant Math.PI for the value of
. This constant is more precise than the value
3.14159. Class Math is declared in the java.lang package, so you need not import it.] Use the fol-
lowing formulas ( r is the radius):
diameter = 2 r
circumference = 2
π
π
r
π
r 2
The user should also be prompted for a set of coordinates in addition to the radius. Then draw the
circle and display its diameter, circumference and area, using an Ellipse2D.Double object to repre-
sent the circle and method draw of class Graphics2D to display it.
13.18 (Screen Saver) Write an application that simulates a screen saver. The application should
randomly draw lines using method drawLine of class Graphics . After drawing 100 lines, the appli-
cation should clear itself and start drawing lines again. To allow the program to draw continuously,
place a call to repaint as the last line in method paintComponent . Do you notice any problems with
this on your system?
13.19 (Screen Saver Using Timer ) Package javax.swing contains a class called Timer that is capa-
ble of calling method actionPerformed of interface ActionListener at a fixed time interval (speci-
area =
 
Search WWH ::




Custom Search