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.
- Draw a Polygon in Java Applet
- Draw a Smiley in Java Applet
- Draw a Chessboard in Java Applet
- Draw an Olympic Symbol in Java Applet
- Java Applet | Draw a line using drawLine() method
- Java Applet Basics
- Java Applet | Digital Stopwatch
- Java Applet | How to display a Digital Clock
- Java Applet | How to display an Analog Clock
- Java Code for Moving Text | Applet | Thread
- Java Applet | Implementing Flood Fill algorithm
- JavaFX | Rectangle and Rounded Rectangle with examples
- Rectangle with Maximum Area using Java Pair
- Java Program for Maximum sum rectangle in a 2D matrix | DP-27
- JavaFX | Ellipse with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.