You are on page 1of 11

CO_IF_22412_UO3

Sneha Patange, Lecturer, Vidyalankar Polytechnic

Date: 11 Feb 2021

MSBTE LEAD: Learning at your Doorstep


Unit 05 :
Java Applets and Graphics
Programming

Written by

Sneha Sharad Patange


Lecturer, Department of Computer engineering, [NBA Accredited],Vidyalankar Polytechnic,
Mumbai
Unit Outcome 3: Develop program
for implementing a given
geometric shape

Written by

Sneha Sharad Patange


Lecturer, Department of Computer Engineering[NBA Accredited],Vidyalankar Polytechnic,
Mumbai
Unit Outcome 3e: Student should
understand how to draw and fill
polygon

Written by

Sneha Sharad Patange


Lecturer, Department of Computer Engineering[NBA Accredited],Vidyalankar Polytechnic,
Mumbai
What we will learn today

 Syntax and description to drawPolygon () and Key takeaways


We should able to implement a code to draw and fill Polygon
using drawPolygon () and fillPolygon () method respectively

Sneha Sharad Patange


Lecturer, Department of Computer Engineering [NBA Accredited],Vidyalankar Polytechnic,
Mumbai

Page 5 Maharashtra State Board of Technical Education 4 July 2020


Concept Map

drawPolygon ()
Syntax and
& fillPolygon() Example
description
method

Page 6 Maharashtra State Board of Technical Education 4 July 2020


Learning Objective/ Key learning

 syntax and description- drawPolygon () and fillPolygon () method


 To draw Polygon using drawPolygon () method
 To draw filled Polygon using fillPolygon () method

Page 7 Maharashtra State Board of Technical Education 4 July 2020


Graphics class – 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

Page 8 Maharashtra State Board of Technical Education 4 July 2020


Graphics class – 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

Page 9 Maharashtra State Board of Technical Education 4 July 2020


Example - To draw filled polygon using drawPolygon () and fillPolygon()method

/*<applet code = "Triangle" width = 400 height =


400>
</applet>*/
import java.awt.*;
import java.applet.*;
public class Triangle extends Applet
{
Int x1 = {110,170,50,110};
Int y1 = {50,100,100,50};
int n = 4;
public void paint(Graphics g)
{
g.setColor(Color.red);
g.fillPolygon(x,y,n);
g.setColor(Color.black);
g.drawString("Triangle", 90,150);}}

Page 10 Maharashtra State Board of Technical Education 4 July 2020


Thank You

Page 11 Maharashtra State Board of Technical Education 4 July 2020

You might also like