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
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 String in Oval
Post your Comment