Advance Desktop Applications - Lecture 8
Advance Desktop Applications - Lecture 8
The upper-left corner of computer screen has coordinates (0,0) it means both
x and y coordinate has values 0.
package GraphicsProgramming;
import java.awt.*;
import java.applet.*;
Syntax
void drawRect(int top, int left, int width, int height)
void fillRect(int top, int left, int width, int height)
g.drawRoundRect(190,10,60,50,15,15);
g.fillRoundRect(70,90,140,100,30,40);
}
The Graphics class does not contain any method for circles or ellipses.
To draw an ellipse, use drawOval(). To fill an ellipse, use fillOval().
Syntax
void drawOval(int top, int left, int width, int height)
void fillOval(int top, int left, int width, int height)
}
KABUL UNIVERSITY Monday, July 29, 2024 15
KABUL UNIVERSITY Monday, July 29, 2024 16
DRAWING ARCS
An arc is a part of oval. Arcs can be drawn with draw Arc() and
fillArc() methods.
Syntax
void drawArc(int top, int left, int width, int height, int startAngle, int
arcAngle)
void fillArc(int top, int left, int width, int height, int startAngle, int
arcAngle)
g.drawArc(10,100,70,80,0,175);
g.drawArc(200,80,80,80,0,180);
}
}
KABUL UNIVERSITY Monday, July 29, 2024 18
KABUL UNIVERSITY Monday, July 29, 2024 19
POLYGON
g.drawPolygon(xpoints,ypoints,num);
}
KABUL UNIVERSITY
} Monday, July 29, 2024 21
KABUL UNIVERSITY Monday, July 29, 2024 22
CODE EX2
package GraphicsProgramming;
import java.awt.*;
import java.applet.*;
public class PolygonEx6 extends Applet {
public void paint(Graphics g)
{
int xs[]={100,160,220};
int ys[]={60,20,60};
g.fillPolygon(xs,ys,3);
g.drawRect(100, 60, 120, 120);
g.drawRect(140, 120, 30, 60);
}