import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
//import java.awt.event.WindowAdapter;
public class ProgressMonitorExample extends JPanel
{
public static void main(String args[])
{
JFrame myFrame =new JFrame("进程条");
ProgressMonitorExample progressMonitorExample=new ProgressMonitorExample ();
myFrame.getContentPane().add("CENTER",progressMonitorExample);
myFrame.setSize(200,100);
myFrame.addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
myFrame.setVisible(true) ;
}
}
//进程类
class ProgressThread extends Thread
{
ProgressMonitor monitor;
boolean stopStatus=false;
int min=0;
int max=50;
//构造函数
public ProgressThread(Component parent)
{
ProgressMonitor monitor= new ProgressMonitor(parent ,"程序的线程","Not Started",min,max) ;
// addActionListener(new ActionListener(monitor));
}
//停止
public void setStop(boolean value)
{
stopStatus=value;
}
//运行
public void run()
{
monitor.setNote("Started");
for(int x=min;x<=max;x++)
{
if(stopStatus)
{
monitor.close();
break;
}
else
{
monitor.setProgress(x);
monitor.setNote(""+(x*2)+"%");
try{
sleep(0);
}
catch(InterruptedException e)
{
//Ignore Exceptions
}
}
}
}
}
阅读(4072) | 评论(1) | 转发(0) |