0% found this document useful (0 votes)
104 views

Import Import Public Class Extends: / Java Program To Create and Fill Shapes Using Applet

This Java program uses an applet to draw and fill different shapes. The shapes include a square, pentagon, circle, oval, rectangle, and triangle. For each shape, the program draws the outline in black and then fills the interior in yellow. The applet initializes with a white background and uses the paint method to draw the shapes by specifying coordinates for polygons or ovals.

Uploaded by

Jerlin sundari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
104 views

Import Import Public Class Extends: / Java Program To Create and Fill Shapes Using Applet

This Java program uses an applet to draw and fill different shapes. The shapes include a square, pentagon, circle, oval, rectangle, and triangle. For each shape, the program draws the outline in black and then fills the interior in yellow. The applet initializes with a white background and uses the paint method to draw the shapes by specifying coordinates for polygons or ovals.

Uploaded by

Jerlin sundari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

/*Java Program to Create and Fill Shapes using Applet*/


2. import java.applet.*;
3. import java.awt.*;
4. public class Shapes extends Applet
5. {
6. //Function to initialize the applet
7. public void init()
8. {
9. setBackground(Color.white);
10. }
11. //Function to draw and fill shapes
12. public void paint(Graphics g)
13. {
14. //Draw a square
15. g.setColor(Color.black);
16. g.drawString("Square",75,200);
17. int x[]={50,150,150,50};
18. int y[]={50,50,150,150};
19. g.drawPolygon(x,y,4);
20. g.setColor(Color.yellow);
21. g.fillPolygon(x,y,4);
22. //Draw a pentagon
23. g.setColor(Color.black);
24. g.drawString("Pentagon",225,200);
25. x=new int[]{200,250,300,300,250,200};
26. y=new int[]{100,50,100,150,150,100};
27. g.drawPolygon(x,y,6);
28. g.setColor(Color.yellow);
29. g.fillPolygon(x,y,6);
30. //Draw a circle
31. g.setColor(Color.black);
32. g.drawString("Circle",400,200);
33. g.drawOval(350,50,125,125);
34. g.setColor(Color.yellow);
35. g.fillOval(350,50,125,125);
36. //Draw an oval
37. g.setColor(Color.black);
38. g.drawString("Oval",100,380);
39. g.drawOval(50,250,150,100);
40. g.setColor(Color.yellow);
41. g.fillOval(50,250,150,100);
42. //Draw a rectangle
43. g.setColor(Color.black);
44. g.drawString("Rectangle",300,380);
45. x=new int[]{250,450,450,250};
46. y=new int[]{250,250,350,350};
47. g.drawPolygon(x,y,4);
48. g.setColor(Color.yellow);
49. g.fillPolygon(x,y,4);
50. //Draw a triangle
51. g.setColor(Color.black);
52. g.drawString("Traingle",100,525);
53. x=new int[]{50,50,200};
54. y=new int[]{500,400,500};
55. g.drawPolygon(x,y,3);
56. g.setColor(Color.yellow);
57. g.fillPolygon(x,y,3);
58. }
59. }
60. /*
61. <applet code = Shapes.class width=600 height=600>
62. </applet>
63. */

You might also like