0% found this document useful (0 votes)
5 views2 pages

LAB-5 JAVA (Applets)

The document outlines a series of tasks for creating Java applets that perform various drawing operations. Each task specifies the graphical method to be used, such as drawing shapes, setting colors, and displaying text. The tasks range from simple operations like drawing lines and rectangles to more complex ones like creating a smiley face and a flower with petals.

Uploaded by

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

LAB-5 JAVA (Applets)

The document outlines a series of tasks for creating Java applets that perform various drawing operations. Each task specifies the graphical method to be used, such as drawing shapes, setting colors, and displaying text. The tasks range from simple operations like drawing lines and rectangles to more complex ones like creating a smiley face and a flower with petals.

Uploaded by

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

1. Question: Create an applet that displays the text "Hello, Applet!

" at position (100,


100). Method to Use: g.drawString("Hello, Applet!", x, y);
2. Question: Write an applet that draws a rectangle with width 150 and height 100.
Method to Use: g.drawRect(x, y, width, height);
3. Question: Write an applet that draws a circle with a radius of 50 pixels. Method to
Use: g.drawOval(x, y, diameter, diameter);
4. Question: Create an applet that draws a line from coordinates (50, 50) to (200, 200).
Method to Use: g.drawLine(x1, y1, x2, y2);
5. Question: Write an applet that draws an oval with width 120 and height 80. Method
to Use: g.drawOval(x, y, width, height);
6. Question: Write an applet that sets the background color to light blue. Method to
Use: setBackground(Color.colorName);
7. Question: Create an applet that draws a filled rectangle with a width of 200 and
height of 100. Method to Use: g.fillRect(x, y, width, height);
8. Question: Write an applet that draws a filled oval with width 150 and height 100.
Method to Use: g.fillOval(x, y, width, height);
9. Question: Write an applet that draws a flower with petals using ovals. The flower
should have a central circular part and 6 petal-like ovals around it. Methods to Use:

g.setColor(Color.yellow); g.fillOval(x, y, diameter, diameter); // For


the center of the flower

g.setColor(Color.pink); g.fillOval(x, y, width, height); // For the


petals

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:

g.setColor(Color.yellow); g.fillOval(x, y, diameter, diameter); // For


the face

g.setColor(Color.black); g.fillOval(x, y, diameter, diameter); // For


the eyes

g.setColor(Color.black); g.drawArc(x, y, width, height, startAngle,


arcAngle); // For the smile

You might also like