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

Programming Excercise, I have to Create a program that determine the shippi...

I have to Create a program that determine the shipping cost for an order based on he following chart: From To Price $0.00 $19.99 $2.95 $20.00 $49.99 $3.95

Need software protection with data files encryption, Need Software protecti...

Need Software protection with data files encryption Project Description: I am use to Chinese dongle sense lock clave 2, i need to prepare to dongle encryption tool same appli

What is an immutable object, What is an immutable object? An immutable ...

What is an immutable object? An immutable object is one that we can't change once it's created. Steps involved in creation of an immutable object are: Make all of its data f

Inheritance, Draw an inheritance hierarchy to represent a shoe object. The...

Draw an inheritance hierarchy to represent a shoe object. The base class should have derived classes of Dress Shoes, Tennis Shoes and Boots.

How many iterations would this for loop run for, How many iterations would ...

How many iterations would this ‘for' loop run for? for ( x = 50 ; x document.write ( x ) ; } Answer: 50 iterations

Vending machine, i have got project of Vending machine. would you please he...

i have got project of Vending machine. would you please help me about how to start and how to use coding.thanks

Differentiation between if statement and a switch statement, Differentiatio...

Differentiation between if statement and a switch statement ?

Explain the polymorphism principle, Explain the Polymorphism principle. ...

Explain the Polymorphism principle. Polymorphism can be referred as one name many forms. It's the ability of methods to behave differently, relying upon the object who is calli

What is a relational database, What is a Relational Database? Give the name...

What is a Relational Database? Give the names of any three RDBMS software? Database consist of two or more then two tables are called Relational database. Oracle dabatbase S

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