LAB-5 JAVA (Applets)
LAB-5 JAVA (Applets)
10. Question: Write an applet that draws a line from (30, 30) to (200, 30) with a red
color. Method to Use: g.setColor(Color.red); g.drawLine(x1, y1, x2, y2);
11. Question: Create an applet that draws three lines: one horizontal, one vertical, and
one diagonal. Method to Use: g.drawLine(x1, y1, x2, y2);
12. Question: Create an applet that draws three rectangles with different sizes and
positions. Method to Use: g.drawRect(x, y, width, height);
13. Question: Write an applet that draws and fills a triangle with three points. Method to
Use: int[] xPoints = {x1, x2, x3}; int[] yPoints = {y1, y2, y3};
g.fillPolygon(xPoints, yPoints, 3);
14. Question: Write an applet that draws a circle with a blue border and a white fill.
Method to Use: g.setColor(Color.blue); g.drawOval(x, y, diameter,
diameter); g.setColor(Color.white); g.fillOval(x, y, diameter,
diameter);
15. Question: Create an applet that draws a rectangle with rounded corners. Method to
Use: g.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
16. Question: Write an applet that displays the text "Java Applet" with a bold, italic font.
Method to Use: Font font = new Font("Serif", Font.BOLD | Font.ITALIC,
20); g.setFont(font); g.drawString("Java Applet", x, y);
17. Question: Write an applet that draws an ellipse with width 200 and height 100.
Method to Use: g.drawOval(x, y, width, height);
18. Question: Write an applet that draws a transparent rectangle with a red border.
Method to Use: g.setColor(new Color(255, 0, 0, 50)); g.fillRect(x, y,
width, height);
19. Question: Write an applet that draws a rectangle and changes its color randomly each
time the applet is loaded. Method to Use: g.setColor(new
Color((int)(Math.random() * 0x1000000))); g.fillRect(x, y, width,
height);
20. Question: Write an applet that draws a five-pointed star. Method to Use: Use
g.drawPolygon() with the coordinates of the star's points.
21. Question: Create an applet that draws a filled hexagon. Method to Use: int[]
xPoints = {x1, x2, x3, x4, x5, x6}; int[] yPoints = {y1, y2, y3, y4,
y5, y6}; g.fillPolygon(xPoints, yPoints, 6);
22. Question: Create an applet that draws a smiley face using circles and arcs. The
smiley face should have a yellow face, black eyes, and a smiling mouth.
Methods to Use: