Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Online Training

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
Print Button
 
Training Index

2D Text Tutorial
Exercises

By Monica Pawlan

[Tutorial Contents]

This page contains the exercises for all the lessons in this tutorial. When you click the submit button for each set of questions, another page appears with the correct answers.


Exercise 1: Using Fonts

  1. A font gets its characteristic look from what?
    A. Characters.
    B. Glyphs.
    C. Point size.
    D. Its derived font.

  2. Which code segment creates a font?
    A. String aString=boldFont.getFamily();
    B. String aString=boldFont.getFontName();
    C. String aString=boldFont.getName();
    D. Font boldFont=aFont.deriveFont(Font.BOLD, 12);
Go to:
Lesson 1: Using Fonts
Lesson 2: Drawing Styled Text

Exercise 2: Drawing Styled Text

  1. How do your create a text string with an interesting fill pattern?
    A. Create a TextAttribute object with and call its fillPattern method.
    B. Create a Font object from an Image object.
    C. Create a Shape from the TextLayout's outline, set the graphics context clip area to that Shape, and draw the image.
    D. Set the graphics context's fill to an Image object.

  2. What does this code segment do?
    Font f=new Font("Times", Font.BOLD, 24);
    AttributedString ats=new AttributedString("Magic");
    ats.addAttribute(TextAttribute.FONT, f);
    ats.addAttribute(TextAttribute.UNDERLINE, 
    		TextAttribute.UNDERLINE_ON);
    AttributedCharacterIterator iter=ats.getIterator();
    
    FontRenderContext frc=g2.getFontRenderContext();
    tl=new TextLayout(iter, frc);
    g2.setColor(Color.red);
    tl.draw(g2, (float)30, (float)50); 
    

    A. Draws a text layout with font and underline attributes.
    B. Sets an underline attribute on the graphics context.
    C. Draws a text layout with no attributes.
    D. Sets an underline attribute on the font.
Go to:
Lesson 2: Drawing Styled Text
Lesson 3: Interacting with Styled Text

Exercise 3: Interacting with Styled Text

  1. How do you calculate the current insertion point moving right?
    A. By starting with a TextHitInfo object that represents the current insertion point, and calling TextLayout.getCaretShapes when the right arrow key is pressed.

    B. By starting with a TextHitInfo object that represents the current insertion point, and calling TextLayout.getHitTestChar when the right arrow key is pressed.

    C. By starting with a TextHitInfo object that represents the current insertion point, and calling TextLayout.getNextLeftHit when the right arrow key is pressed.

    D. By starting with a TextHitInfo object that represents the current insertion point, and calling TextLayout.getNextRightHit when the right arrow key is pressed.

  2. What is the best way to draw the highlight region for selected text?
    A. Draw the highlight region first and draw the text over it.
    B. Draw the text first and draw the highlight region over it.
    C. It does not matter.
    D. Draw the lighter color first, and put the darker color over it.
Go to:
Lesson 3: Interacting with Styled Text
Lesson 4: Foreign Language Support

Exercise 4: Foreign Language Support

  1. What is bidirectional text?
    A. Text that runs right-to-left.
    B. French.
    C. Sanskrit.
    D. Text that includes right-to-left and left-to-right text.

  2. Which statement about bidirectional text is true?
    A. A TextLayout object needs extra code to draw bidirectional text.
    B. The TextHitInfo object cannot determine the location of a user click without the help of the TextLayout.CaretPolicy class.
    C. The source text does not map one-to-one to the displayed text.
    D. When the end user presses an Arrow key, the caret moves in the opposite direction on the display.
Go to:
Lesson 4: Foreign Language Support
Lesson 5: Other Methods

Exercise 5: Other Methods

  1. A TextLayout object currently uses what type of baseline?
    A. Centered.
    B. Hanging.
    C. Roman.
    D. Centered Roman.

  2. What is the advance of a TextLayout?
    A. The amount of white space at the beginning of the string.
    B. The amount of white space at the end of the string.
    C. The space before a directional boundary.
    D. The length of the TextLayout object.
Go to:
Lesson 5: Other Methods

Print Button
[ This page was updated: 21-Sep-2000 ]
Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary | Feedback | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-2000 Sun Microsystems, Inc.
All Rights Reserved. Terms of Use. Privacy Policy.