What is the role of fonts in java explain with example, JAVA Programming

Assignment Help:

What is the role of fonts in java explain with example?

You've already seen one instance of drawing text in the HelloWorldApplet program of the last chapter. You call the drawString() method of the Graphics object. This method is passed the String you need to draw as well as an x and y coordinate. If g is a Graphics object, then the syntax is

g.drawString(String s, int x, int y)

The String is easily the text you want to draw. The two integers are the x and y coordinates of the lower left-hand corner of the String. The String will be drawn above and to the right of this point. Therefore letters along with descenders such as y and p may have their descenders drawn below the line.

Until now all the applets have used the default font, probably a few variation of Helvetica though this is platform dependent. Therefore unlike HTML Java does permit you to choose your fonts. Java implementations are guaranteed to have a serif font like Times which can be accessed along with the name "Serif", a monospaced font like courier which can be accessed along with the name "Mono", and a sans serif font like Helvetica which can be accessed along with the name "SansSerif".

The subsequent applet lists the fonts available on the system it's running on. It does this through using the getFontList() method from java.awt.Toolkit. This technique returns an array of strings containing the names of the available fonts. These might or may not be the similar as the fonts installed on your system. It's implementation dependent while or not all the fonts a system has are available to the applet.

import java.awt.*;
import java.applet.*;

public class FontList extends Applet {

private String[] availableFonts;

public void init () {

Toolkit t = Toolkit.getDefaultToolkit();
availableFonts = t.getFontList();

}

public void paint(Graphics g) {

for (int i = 0; i < availableFonts.length; i++) {
g.drawString(availableFonts[i], 5, 15*(i+1));
}
}

}


Related Discussions:- What is the role of fonts in java explain with example

What is asynchronous messaging, What is asynchronous messaging? Queue An...

What is asynchronous messaging? Queue Ans) Asynchronous messaging includes a client that does not wait for a message from the server. An event is used to trigger a message from

What are the advantages of jms, One of the principal benefits of JMS messag...

One of the principal benefits of JMS messaging is that it's asynchronous. Thus not all the pieces require to be up all the time for the application to function as a whole.

Explain exception classes, OOPS with Java 1. Explain any five buzz word...

OOPS with Java 1. Explain any five buzz words in Java. 2. Explain exception classes and also explain common exceptions in java. 3. Explain primitive and abstract data typ

What are application softwares, What are application softwares? List down t...

What are application softwares? List down the names of three application software's. Definition: Application Software are in which software then can interact directory along

Write a java windowed application, For this assignment, you will write a Ja...

For this assignment, you will write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result. Overview of the applic

Inheritance, Inheritance - is the inclusion of state and behavior of a ba...

Inheritance - is the inclusion of state and behavior of a base class in a derived class so that they are accessible in that derived class. The key benefit of Inheritance is that

Conditional Operators, I need a chart and how this works with java? The fun...

I need a chart and how this works with java? The functions itself.

Linked list, i want code for to print prime numbers in the linked list queu...

i want code for to print prime numbers in the linked list queue and stack and array in java programming

Registered objects in a rmiregistry, How to get all the registered objects ...

How to get all the registered objects in a rmiregistry? Ans) Using list method of Naming Class.

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd