This section illustrates you how to draw the calendar icon.
An icon is a pictorial image used in a graphical user interface to represent a program, a command, a link to a Web page, etc. To show calendar icon, we have used the class Calendar. The Calendar class provides methods for converting a specific instant in time and a set of calendar fields, like year, month, day, hour etc, and for manipulating the calendar fields.
The Font class defines the font for the date, day and month. The object of class FontMetrics encapsulates information to render a particular font on a particular screen. The Icon class gives the method paintIcon() which describes the structure of icon.
The cal.get(Calendar.DAY_OF_WEEK) returns the day of the week. The Integer.toString (cal.get (Calendar . DAY_OF_MONTH)) converts the integer into string and returns the date of the month. The cal.get(Calendar.MONTH) returns the month of the year.
The method stringWidth(st) calculates the width of the entire string in pixels. The drawString() method draws the specified text string at the specified location with the specified font.
Here is the code of CalendarIconExample.java
import java.awt.*;
|
Output will be displayed as:
![]()
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Show Calendar Icon View All Comments
Post your Comment