Chapter 3, 3.7

1. Write the code segments that would draw the following objects in the graphics context g:

a. A filled rectangle with corner point (45,20) and size 100 by 50.

-g.drawRect(45, 20, 100,50)

b. A line segment with end points(20,20) and (100,100)

-g.drawLine(20,20,100,100)

c. A circle with center point (100,100) and radius 50.

-g.drawOval(100,100,50,50)

d. A triangle with vertices (100,100), (50,50),and (200,200)

-g.drawLine(100,100,50,50)

g.drawLine(50,50,200,200)

g.drawLine(200,200,100,100)

2. Describe the design of a program that displays a filled blue rectangle on a red background.

- public ColorPanel(Color backColor){

setBackground(Color.red)

}

g.setColor(Color.blue)

g.fillRect(10,10,50,60)

3. How does one compute the center point of a panel.

- We can use a getWidth and getHeight method to do so.

4. List the three properties of a text font.

-The three properties are name, style and size.

Leave a Comment