Java applets are application that can be executed in web browsers or applet viewers . We can draw shapes on the Java applet.
In this article we will draw a ellipse on Java applet by two ways . By using the drawOval(int x, int y, int width, int height) or by using mathematical formula (X= A * sin a, Y= B *cos a, where A and B are major and minor axes and a is the angle ) .
Similarly, we will draw a rectangle on Java applet by two ways . By using the drawRect(int x, int y, int width, int height) or by drawing four lines joining the edges .
To draw a ellipse in Java Applet
Let us draw a oval with width 150 and height 100
Input : x and y coordinates 100, 100 respectively Width and height 150 and 100 respectively
To draw a rectangle in Java Applet
We will draw a rectangle of height 200 and width 200 and
At a position 100,100 on the applet.
Input : x and y coordinates 100, 100 respectively Width and height 200 and 200 respectively.
1. Java Program to draw a ellipse using drawOval(int x, int y, int width, int height)
2. program to draw a ellipse using drawLine function
Now we will see how to draw a rectangle in a Java Applet
We can draw rectangle in java applet by two ways.
1. Draw a rectangle using drawRect(int x, int y, int width, int height)
2. Draw a rectangle using drawLine(int x, int y, int x1, int y1)
Note : the following programs might not run in an online compiler please use an offline IDE.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.