Java Reference
In-Depth Information
itself. Real applications using the progress bar will probably be multithreaded. Note that for thread-safe
access to AWT, it is necessary to use the EventQueue.invokeLater() method, described in the
section " Multiple Threads in the PDAP AWT Subset . "
Figure 4.8. The ProgressTest application for testing the ProgressBar component.
Listing 4.7 ProgressTest.java
import java.awt.*;
import java.awt.event.*;
import javax.microedition.midlet.*;
public class ProgressTest extends MIDlet implements
AdjustmentListener {
Frame frame;
ProgressBar pBar = new ProgressBar();
Scrollbar sBar = new Scrollbar();
public ProgressTest() {
frame = new Frame("ProgressBar Test");
sBar = new Scrollbar (Scrollbar.HORIZONTAL, 0, 10, 0, 100);
sBar.addAdjustmentListener(this);
frame.add(pBar, BorderLayout.NORTH);
frame.add(sBar, BorderLayout.SOUTH);
frame.pack();
}
public void adjustmentValueChanged(AdjustmentEvent e) {
pBar.setValue (sBar.getValue());
pBar.repaint();
}
public void startApp() {
frame.show();
}
public void pauseApp() {
}
 
 
Search WWH ::




Custom Search