This section illustrates you how to show the string in Oval.
To show a string in oval, we are providing you an example. A font 'Book Antiqua' is defined to display the string 'WELCOME'. To render the particular font on the screen, we have used the class FontMetrics. The object of FontMetrics class encapsulates all the information.
The method drawOval() draw an oval shape. The char ch = st.charAt(k) retrieves the k character on each iteration. The method getHeight() of class FontMetrics gets the standard height of a line of text in the given font. The method charWidth(ch) of class FontMetrics returns the width of the specified character in the given font.
Following code draws the string in oval:
|g.drawString(String.valueOf(ch), x, y + h);|
Here is the code of ShowFontInOval.java
Output will be displayed as:
Liked it! Share this Tutorial