Program to design an applet which draws a circle (having color BLUE) inside a triangle (having color YELLOW)
Given program will draw a circle inside a triangle. The color of circle is "blue" and triangle having color "yellow". To fill circle with respective colours first we have to set the colour using setColor(Color c) method of Graphics class and then use the fillPolygon() and fillOval( ) method.
The fillPolygon( ) method Fills a closed polygon defined by arrays of x and y coordinates. The syntax for fillPolygon( ) is given below:
void fillPolygon (int[ ] xPoints, int[ ] yPoints, int nPoints)
The fillOval( ) method fills an oval bounded by the specified rectangle with the current color. The rectangle is filled using the graphics context's current color. The syntax for fillOval( ) is given below:
PROGRAM
OUTPUT
C:\>javac CircleInsideTriangle.java
C:\>appletviewer CircleInsideTriangle.java
void fillOval (int x, int y, int width, int height)
PROGRAM
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class CircleInsideTriangle extends Applet {
public void paint(Graphics g) {
// Draws a triangle
int xPoints[] = {120, 220, 30};
int yPoints[] = {30, 220, 220};
g.setColor(Color.YELLOW);
g.fillPolygon(xPoints, yPoints, 3);
// Draws a circle
g.setColor(Color.BLUE);
g.fillOval(90, 120, 70, 70);
}
}
/* <applet code="CircleInsideTriangle" width=250 height=250>
</applet>
*/
OUTPUT
C:\>javac CircleInsideTriangle.java
C:\>appletviewer CircleInsideTriangle.java
Thanks for sharing this amazing post this is the content i really looking for, it's very helpful i hope you will continue your blogging anyway if anyone looking for AutoCAD training institute in delhi contact us +91-9311002620 visit-https://www.htsindia.com/autocad-training-institute
ReplyDeleteI am appreciative of this blog's ability to provide information on such an important subject about Aws Certification in Delhi. I discovered other segments here, and I'm excited to put these new instructions to use.
ReplyDeleteYou've written an excellent post, and you've shared it with us about Software Testing Training Courses Online. Your article provided me with some unique and useful knowledge. I appreciate you sharing this text with us.
ReplyDelete