showAlert(a);
return a;
}
}
// An alert test that displays an alert with
// a gauge whose value is increased every second.
// The alert can be dismissed only after the gauge
// reaches its maximum value.
public class ProgressAlert extends AlertRunner implements CommandListener,
Runnable
{
private static final int MAX = 10;
public ProgressAlert(String title)
{
super(title);
}
public Alert doAlert()
{
_gauge = new Gauge(null, false, MAX, 0);
_gauge.setValue(0);
_done = false;
_alert = new Alert(getTitle());
_alert.setString("Counts to " + MAX
+ " and then lets you dismiss it");
_alert.setCommandListener(this);
_alert.setIndicator(_gauge);
// Set a _very_ long timeout
_alert.setTimeout(ONE_SECOND * 3600);
showAlert(_alert);
new Thread(this).start();
return _alert;
}
public void commandAction(Command c, Displayable d)
{
if (_done || _gauge.getValue() >= MAX)
{
showList();
}
}
private void done()
{
_alert.addCommand(new Command("Done", Command.OK, 1));
_done = true;
}
// A thread that bumps the value of the counter
// every second.
public void run()
{
int val = _gauge.getValue();
try
{
while (val < MAX)
{
Thread.sleep(ONE_SECOND);
_gauge.setValue(++val);
}
} catch (InterruptedException e)
{
}