Problem 1
Fill in the blanks in each of the following statements: a) In Java 2D, method _______of class________sets the characteristics of a line used to draw a shape. b) Class ________ helps specify the fill for a shape such that the fill gradually changes from one color to another. c) The _______ method of class Graphics draws a line between two points. d) RGB is short for_______ ,_________ and .___________ e) Font sizes are measured in units called ._________ f) Class ________ helps specify the fill for a shape using a pattern drawn in a Buffered- Image.
Problem 2
State whether each of the following is true or false. If false, explain why. a) The first two arguments of Graphics method draw0val specify the center coordinate of the oval. b) In the Java coordinate system, \(x\) -values increase from left to right. c) Graphics method fillPolygon draws a filled polygon in the current color. d) Graphics method drawArc allows negative angles. e) Graphics method getSize returns the size of the current font in centimeters. f) Pixel coordinate (0,0) is located at the exact center of the monitor.
Problem 3
Find the error(s) in each of the following and explain how to correct the error(s). Assume that \(g\) is a Graphics object. a) \(g \cdot\) setFont \((\text { "SansSerif" })\) b) \(g\). erase \((x, y, w, h)\) // clear rectangle at \((x, y)\) c) Font \(f=\) new Font \((\text { "Serif", Font.BOLDITALIC, } 12\) ); d) \(g \cdot\) setColor (255,255,0)\(; \quad / /\) change color to yellow
Problem 4
Fill in the blanks in each of the following statements: a) Class _____ of the Java 2 D API is used to draw ovals. b) Methods draw and fill of class Graphics2D require an object of type_________as their argument. c) The three constants that specify font style are _______, _________and______ d) Graphics2D method _________sets the painting color for Java 2D shapes.
Problem 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.
Problem 9
{Random Triangles})\( Write an application that displays randomly generated triangles in different colors. Each triangle should be filled with a different color. Use class GeneralPath and method \)f i 11$ of class Graphics2D to draw the triangles.
Problem 16
(Drawing Cubes) Write an application that draws a cube. Use class GeneralPath and method draw of class Graphics2D.
Problem 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 application 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?
Problem 29
{ Random Colors })$ Modify Exercise 12.28 to draw each of the 20 randomly sized shapes in a randomly selected color. Use all 13 predefined Color objects in an array of Colors.