Title: Making a Smile Face
1Making a Smile Face
2Code you have
- Â Â Â Â Â Â Â DrawingPanel panel new DrawingPanel
(300, 200)Â Â Â Â Â Â Â Graphics g panel.getGraphics
( )Â Â Â Â Â Â Â Â Â Â Â Â Â Â //first smiley
face       g.setColor (Color.YELLOW)       g.fi
llOval (20, 10, 50, 50)Â Â Â Â Â Â Â g.setColor
(Color.BLACK)Â Â Â Â Â Â Â g.fillOval (32, 25, 7,
7)Â Â Â Â Â Â Â g.fillOval (50, 25, 7, 7)
            g.drawOval (30, 37, 30, 15) //
drawOval instead of fill to get a
line       g.setColor (Color.YELLOW)// draw the
blackout box       g.fillRect (30, 33, 30,
10)Â Â Â Â Â Â Â Â Â Â Â Â Â Â //second smiley
face       g.setColor (Color.YELLOW)       g.fi
llOval (230, 10, 50,50)Â Â Â Â Â Â Â g.setColor
(Color.BLACK)Â Â Â Â Â Â Â g.fillOval (242, 25, 7,
7)Â Â Â Â Â Â Â g.fillOval (260, 25, 7,
7)Â Â Â Â Â Â Â g.drawOval (240, 37, 30,
15)Â Â Â Â Â Â Â g.setColor (Color.YELLOW)Â Â Â Â Â Â Â g.fi
llRect (240, 33, 30, 10)
3Graphics methods
Method name Description
drawLine(x1, y1, x2, y2) line between points (x1, y1), (x2, y2)
drawOval(x, y, width, height) draws outline of largest oval that fits in a box of size width height with top-left corner at (x, y)
drawRect(x, y, width, height) draws outline of rectangle of size width height with top-left corner at (x, y)
drawString(text, x, y) writes text with bottom-left corner at (x, y)
fillOval(x, y, width, height) fills largest oval that fits in a box of size width height with top-left corner at (x,y)
fillRect(x, y, width, height) fills rectangle of size width height with top-left corner at (x, y)
setColor(Color) Sets Graphics to paint subsequent shapes in the given color
4Finding relationships
- Â Â Â Â Â Â Â DrawingPanel panel new DrawingPanel
(300, 200)Â Â Â Â Â Â Â Graphics g panel.getGraphics
( )Â Â Â Â Â Â Â Â Â Â Â Â Â Â //first smiley
face       g.setColor (Color.YELLOW)       g.fi
llOval (20, 10, 50, 50)Â Â Â Â Â Â Â g.setColor
(Color.BLACK)Â Â Â Â Â Â Â g.fillOval (32, 25, 7,
7)Â Â Â Â Â Â Â g.fillOval (50, 25, 7, 7)
            g.drawOval (30, 37, 30, 15) //
drawOval instead of fill to get a
line       g.setColor (Color.YELLOW)// draw the
blackout box       g.fillRect (30, 33, 30,
10)Â Â Â Â Â Â Â Â Â Â Â Â Â Â //second smiley
face       g.setColor (Color.YELLOW)       g.fi
llOval (230, 10, 50,50)Â Â Â Â Â Â Â g.setColor
(Color.BLACK)Â Â Â Â Â Â Â g.fillOval (242, 25, 7,
7)Â Â Â Â Â Â Â g.fillOval (260, 25, 7,
7)Â Â Â Â Â Â Â g.drawOval (240, 37, 30,
15)Â Â Â Â Â Â Â g.setColor (Color.YELLOW)Â Â Â Â Â Â Â g.fi
llRect (240, 33, 30, 10)
What is the relationship between the 20,10 Big
Circle start and the 32,25 eyes?
32 is 12 over and 15 down, so You can set x 20
and y 10 And make the big circle with
g.fillOval(x,y,50,50) And make the eye with
g.fillOval(x12,y15,7,7)
5Coded with relationships
- Â Â Â Â Â Â Â DrawingPanel panel new DrawingPanel
(300, 200)Â Â Â Â Â Â Â Graphics g panel.getGraphics
( )Â Â Â Â Â Â int x 20 - int y 10 Â //first smiley
face       g.setColor (Color.YELLOW)       g.fi
llOval (x, y, 50, 50)Â Â Â Â Â Â Â g.setColor
(Color.BLACK)Â Â Â Â Â Â Â g.fillOval (x12, y15, 7,
7)Â Â Â Â Â Â Â g.fillOval (x30, y15, 7, 7)
            g.drawOval (x10, y17, 30, 15) //
drawOval instead of fill to get a
line       g.setColor (Color.YELLOW)// draw the
blackout box       g.fillRect (x10, y23, 30,
10)Â Â Â Â Â x 230 - y 10Â Â Â Â Â Â Â Â //second smiley
face       g.setColor (Color.YELLOW)       g.fi
llOval (x, y, 50, 50)Â Â Â Â Â Â Â g.setColor
(Color.BLACK)Â Â Â Â Â Â Â g.fillOval (x12, y15, 7,
7)Â Â Â Â Â Â Â g.fillOval (x30, y15, 7, 7)
            g.drawOval (x10, y17, 30, 15) //
drawOval instead of fill to get a
line       g.setColor (Color.YELLOW)// draw the
blackout box       g.fillRect (x10, y23, 30,
10)
6Coded with Methods
- Â Â Â Â Â Â Â DrawingPanel panel new DrawingPanel
(300, 200)Â Â Â Â Â Â Â Graphics g panel.getGraphics
( ) Â smile(10,20) //first smiley face
smile (230,10) // second face - public static void smile(int x, int y)
- g.setColor (Color.YELLOW)Â Â Â Â Â Â Â g.f
illOval (x, y, 50, 50)Â Â Â Â Â Â Â g.setColor
(Color.BLACK)Â Â Â Â Â Â Â g.fillOval (x12, y15, 7,
7)Â Â Â Â Â Â Â g.fillOval (x30, y15, 7, 7)
            g.drawOval (x10, y17, 30, 15) - // drawOval instead of
fill to get a line       g.setColor
(Color.YELLOW)// draw the blackout
box       g.fillRect (x10, y23, 30, 10)    Â