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

Need to code using java in netbeans for my dissertation, I need to code usi...

I need to code using java in netbeans for my dissertation which is in data mining domain...deals with privacy preserving of sensitive rules or items using association rule hiding

Use the constructor, Can we use the constructor, instead of init(), to init...

Can we use the constructor, instead of init(), to initialize servlet? Ans) Yes. Of course you can use the constructor instead of init(). There's nothing to stop you. But you sho

Object diagrams, Object diagrams define instances instead of classes. They ...

Object diagrams define instances instead of classes. They are useful for illustrating some complicated objects in detail about their recursive relationships.     When

Minimum spanning tree based heuristic, Problem description: A travelling s...

Problem description: A travelling salesman wants to make a tour of the cities and returns back to the starting point. What is the minimum length tour? Formal Definiti

Difference b/w deep cloning and shallow cloning of object, The default natu...

The default nature of an object's clone() function automatically provides a shallow copy. So to need a deep copy the classes have to be edited or adjusted.   Shallow co

What are the basic advantages of jms, JMS is asynchronous in nature. Theref...

JMS is asynchronous in nature. Therefore not all the pieces need to be up all the time for the application to function as a whole. Even if the receiver is down the MOM will kept th

How can we include images in a web page using html and java, How can we inc...

How can we include images in a web page using HTML and Java script? Image in HTML Image in Javascript Images in JavaScript could be manipulated in several ways using the buil

Overloading method, QUESTION 3: Overloaded methods Write the overloaded me...

QUESTION 3: Overloaded methods Write the overloaded method named average () for each of the following problems: a) The first method receives THREE (3) integer values and returns

Explain unicode in java, Explain unicode in java? Java uses the Unicode...

Explain unicode in java? Java uses the Unicode character set. It is a two-byte character code set which has characters representing almost overall characters in almost all huma

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