站内搜索: 请输入搜索关键词
当前页面: 图书首页 > Wireless Java Developing with J2ME, Second Edition

Screens and Tickers - Wireless Java Developing with J2ME, Second Edition

Previous Section Next Section

Screens and Tickers

The remainder of this chapter and all of Chapter 6 are devoted to Screen and its subclasses, which is the left branch of the hierarchy shown in Figure 5-1. Screen is the base class for all classes that represent generalized user interfaces.

Canvas, by contrast, is a base class for specialized interfaces, such as those for games. Canvas will be fully covered later, in Chapter 10.

In the coming sections, we'll explore each of Screen's child classes. Here, I'll briefly describe what all Screens have in common: a title and a ticker. The title is just what you expect: a string that appears at the top of the screen. A ticker is simply a bit of text that scrolls across the top of a Screen; it is named after old-fashioned stock tickers.

In MIDP 2.0, the four methods I'm about to describe are moved from Screen to Displayable. Thus, MIDP 2.0 extends the concept of title and ticker to all Displayables, not just Screens. In MIDP 2.0, the Screen class has no methods.

The title is a text string displayed at the top of the screen. As you saw in Figure 5-3, the title of the screen is "TextBox." Subclasses of Screen have constructors that set the title, but the title may also be accessed using the following methods:

public void setTitle(String newTitle)
public String getTitle()

The ticker is just as easy to access:

public void setTicker(Ticker newTicker)
public Ticker getTicker()

The Ticker class is a simple wrapper for a string. To add a ticker to a screen, you would do something like this:

// Displayable d = ...
Ticker ticker = new Ticker("This is the ticker message!");
d.setTicker(ticker);

Figure 5-5 shows a ticker in action.


Figure 5-5: A ticker scrolls across the top of a screen.

Previous Section Next Section