An icon is an image that shows some concept or specific entity with meaning for the user. To show Oval Icons, we have used the class Container.
Show Oval Icons
In this section, you will studied how to display Oval Icons.
An icon is an image that shows some concept or specific entity with meaning for the user. To show Oval Icons, we have used the class Container. The object of class Container added different components in a list. The order of the list will define the components in a stacking order within the container.
The method setHorizontalTextPosition() returns the horizontal position of the label's text, relative to its image. To arrange the components in a left-to-right flow, like the lines of text in a paragraph, class FlowLayout is used.
Following code draws the icon at the specified location:
public void paintIcon(Component container, Graphics g, int p, int q) { g.drawOval(p, q, width - 1, height - 1); } |
The method paintIcon() is provided by the class Icon.
Here is the code of OvalIconExample.java
import java.awt.*;
|
Output will be displayed as: