Java The Complete Reference, Seventh Edition
This method returns an array of strings that contains the names of the available font families. In addition, thegetAllFonts( )me ...
Creating and Selecting a Font To select a new font, you must first construct aFontobject that describes that font. OneFont const ...
class MyMouseAdapter extends MouseAdapter { SampleFonts sampleFonts; public MyMouseAdapter(SampleFonts sampleFonts) { this.sampl ...
Font getFont( ) Once you have obtained the currently selected font, you can retrieve information about it using various methods ...
which encapsulates various information about a font. Let’s begin by defining the common terminology used when describing fonts: ...
Displaying Multiple Lines of Text Perhaps the most common use ofFontMetricsis to determine the spacing between lines of text. Th ...
694 Part II: The Java Library // Advance to next line. void nextLine(String s, Graphics g) { FontMetrics fm = g.getFontMetrics() ...
Chapter 23: Introducing the AWT: Working with Windows, Graphics, and Text 695 g.setFont(f); drawCenteredString("This is centered ...
696 Part II: The Java Library // Demonstrate text alignment. import java.applet.*; import java.awt.*; import java.awt.event.*; i ...
Chapter 23: Introducing the AWT: Working with Windows, Graphics, and Text 697 g.setFont(f); if(fm == null) { fm = g.getFontMetri ...
case LEFTRIGHT: if(lineW < (int)(d.width*.75)) { g.drawString(line, 0, y); } else { int toFill = (d.width - lineW)/wc; int nu ...
The first three cases indrawString( )are simple. Each aligns the string that is passed in lineto the left or right edge or to th ...
This page intentionally left blank ...
701 24 Using AWT Controls, Layout Managers, and Menus T his chapter continues our exploration of the Abstract Window Toolkit (AW ...
702 Part II: The Java Library Scroll bars Text editing These controls are subclasses ofComponent. Adding and Removing Controls ...
Chapter 24: Using AWT Controls, Layout Managers, and Menus 703 Label( ) throws HeadlessException Label(Stringstr) throws Headles ...
704 Part II: The Java Library Using Buttons Perhaps the most widely used control is the push button. Apush buttonis a component ...
no = new Button("No"); maybe = new Button("Undecided"); add(yes); add(no); add(maybe); yes.addActionListener(this); no.addAction ...
706 Part II: The Java Library getSource( )method to the button objects that you added to the window. To do this, you must keep a ...
Chapter 24: Using AWT Controls, Layout Managers, and Menus 707 which button has been pushed by using its object reference. It is ...
«
32
33
34
35
36
37
38
39
40
41
»
Free download pdf