import sun.net.*;
import sun.net.ftp.*;
public class ProcessBar {
public static void main(String[] args) throws IOException {
final JFrame f = new JFrame("ProgressMonitor Sample");
f.getContentPane().setLayout(new FlowLayout());
JButton b = new JButton("Click me");
f.getContentPane().add(b);
f.pack();
File f1=new File("e://test1//a.rmvb");
final RandomAccessFile getFile =new RandomAccessFile(f1,"rw");
getFile.seek(0);
FtpClient client=new FtpClient("192.168.1.217");
client.login("ftpuser","123456");
client.binary();
TelnetInputStream ftpFile=client.get("/a.rmvb");
final InputStream in=new DataInputStream(ftpFile);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new Thread() {
public void run() {
try {
InputStream in = new FileInputStream("e://anywhere for you.rmvb"); ProgressMonitorInputStream pm = new ProgressMonitorInputStream (f,"Reading file: a.rmvb",in);
public class ProgressList extends JPanel implements Scrollable
{
public ProgressList()
{
super(null);
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
setBackground(Color.WHITE);
}
public Dimension getPreferredScrollableViewportSize()
{
return getPreferredSize();
}
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
{
if (getComponentCount() > 0) {
Component c = getComponent(0);
return c.getHeight();
}
return 0;
}
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)
{
return orientation == SwingConstants.HORIZONTAL ? visibleRect.width : visibleRect.height;
}
public boolean getScrollableTracksViewportWidth()
{
return true;
}
public boolean getScrollableTracksViewportHeight()
{
return true;
}
private static class Progress extends JPanel {
//private static final ImageIcon CANCEL_BTN_ICON = new ImageIcon(ProgressList.class.getResource("imgs/cancelIcon.png"));
//private static final ImageIcon TITLE_ICON = new ImageIcon(ProgressList.class.getResource("imgs/titleIcon.png"));
private static final Color SELECTION_BG = UIManager.getColor("List.selectionBackground");
private static final Color SELECTION_FG = UIManager.getColor("List.selectionForeground");
private static final Color UNSELECTION_BG = new Color(245, 245, 245);
private static final Color UNSELECTION_FG = UIManager.getColor("List.foreground");
private JLabel titleIconLabel = new JLabel();
private JLabel titleLabel = new JLabel();
private JLabel progressInfoLabel = new JLabel();
private JButton cancelBtn = new JButton();
private JProgressBar progressBar = new JProgressBar();
private boolean selected;
final Random random = new Random();
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
final ProgressList progressList = new ProgressList();
JButton btn = new JButton("Start");
btn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
final Progress progress = new Progress("Test Progress - " + (n++), 0, " ");
progressList.add(progress);
progressList.revalidate();
progressList.getParent().repaint();
new Thread() {
public void run()
{
while (true) {
try {
Thread.sleep(2000 + random.nextInt(200));
} catch (InterruptedException e) {
}
int t = progress.getProgress();
if (t >= 100) {
return;
}
t += random.nextInt(20);
t = Math.min(t, 100);
progress.setProgress(t);
progress.setProcessInfo("Progress " + t + "% complete, current time is " + sdf.format(new Date()));
}
}
}.start();
}
});
JPanel btnPane = new JPanel();
btnPane.add(btn);
JScrollPane sp = new JScrollPane(progressList);
JFrame f = new JFrame("Progress List Test");
f.getContentPane().add(sp, BorderLayout.CENTER);
f.getContentPane().add(btnPane, BorderLayout.SOUTH);
f.setSize(400, 400);
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}