You are on page 1of 6

Template: Study Material

<CO5>: <22142>: <Java Programming>: <Develop program for implementing given geometric shape>: <UO3>: <Study Material>

<Sneha Patange> <10/2/2021> <Vijay Patil>

Key words Learning Objective: Diagram/ Picture


Graphics class, Graphic Student should understand how to draw given geometric shape
class methods,drawRect, using graphics class respective method.
drawLine, drawOval,
drawArc, drawPolygon,
fillRect, fillLine, fillOval,
fillArc, fillPolygon

Key Questions Concept Map


Use insert smart art to draw a neat concept map – also connect the
topic to other topics – so student realises why this LO is important
 Explain any four graphic
class methods.
 Write a code to draw a
line.
 Write a code to draw
filled rectangle Graphics class
Syntax and
 Write a code to draw a different Example
description
filled oval methods
 Write a code to draw a
polygon
 Describe a method
used to draw an arc
Explanation of concept:
Graphics class-
 Defined in java.awt (Abstract Window Toolkit)package (
java.awt.Graphics)
 Provide methods for graphics programming
To draw/print text.
To draw simple geometric shapes, lines.
To set font color or background color etc

Graphics class methods-

Graphics class –
drawline () method
Syntax:
drawLine(int x1, int y1, int x2, int y2)

Parameters: The drawLine method takes four arguments:


x1 – It takes the first point’s x coordinate.
y1 – It takes first point’s y coordinate.
x2 – It takes second point’s x coordinate.
y2 – It takes second point’s y coordinate.

Result: This method will draw a line starting from (x1, y1) co-
ordinates to (x2, y2) co-ordinates.

drawRect () method-
Syntax:
drawRect(x,y,w,h);

Parameters: The drawRect method takes four arguments:


x – x coordinate.
y – y coordinate.
w – width of rectangle in pixel
h – height of rectangle in pixel

Result: This method will draw a rectangle starting from (x, y) co-
ordinates with specified width and height
Solved word drawOval () method-
Problem Syntax:
Explain execution
of applet life cycle drawOval(int x1,int y1, int width, int height)
with help of
example? Parameters: The drawOval method takes four arguments:
x1 –point’s x coordinate.
y1 –point’s y coordinate.
width – width of oval
height – Height of oval

Result: This method will draw Oval starting from (x1, y1) co-
ordinates with specified width and height

fillOval () method-
Syntax:
fillOval(int x1,int y1, int width, int height)

Parameters: The fillOval method takes four arguments:


x1 –point’s x coordinate.
y1 –point’s y coordinate.
width – width of oval
height – Height of oval.

Result: This method will draw an Oval starting from (x1, y1) co-
ordinates with specified width and height. This drawn Oval will be
filled with set foreground color.

Explanation of concept:
drawArc () method-

Syntax:
drawArc(int x, int y, int w, int h, int sa, int aa)

Parameters: The drawOval method takes four arguments:


X=x-co-ordinate
Y=y co-ordinate
W=width;
H=height;
Sa=starting angle
Aa=arc angle (sweep angle)

Result: This method draws an arc starting from (x1, y1) co-ordinates
with specified width and height and with specified starting angle and
arc angle around it.
fillOval () method-
Syntax:
fillArc(int x, int y, int w, int h, int sa, int aa)

Parameters: The fillOval method takes four arguments:


X=x-co-ordinate
Y=y co-ordinate
W=width;
H=height;
Sa=starting angle
Aa=arc angle (sweep angle)

Result: This method draws an filled arc starting from (x1, y1) co-
ordinates with specified width and height and also with specified
starting angle and arc angle around it.

drawPolygon () method-
Syntax:
drawPolygon(xp,yp,n)

Parameters: The drawOval method takes four arguments:


Xp= array of x co-ordinates
Yp=array of y co-ordinates
N= total number of points

Result: This method draws Polygon with given x- coordinate and Y-


coordinate array

fillPolygon()method-
Syntax:
fillPolygon(xp,yp,n)

Parameters: The fillOval method takes four arguments:


Xp= array of x co-ordinates
Yp=array of y co-ordinates
N= total number of points

Result: This method draws filled Polygon with given x- coordinate


and Y- coordinate array
Application of Concept/ Examples in real life Link to
YouTube/
OER/ video
Link to any
youtube
that also
explains
either this
concept or
the
application
of this
concept
Open the
link and
then Insert
the link here
– Ctrl+K
OUTPUT:

Key Take away from this LO:


Concept of Java Applet

You might also like