📄 copythreadprogress.java
字号:
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.awt.event.*;
class A
{
public static void main(String [] args)
{
new ProgressFrame();
}
}
class ProgressFrame extends JFrame
{
JButton btn=new JButton("ok");
public ProgressFrame()
{
this.getContentPane().add(btn,"South");
btn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
new Thread(new Copy(new File("E:\\JDK\\kk.dsw"),new File("kk.dsw"))).start();
//proBar.setValue(proBar.getValue()+1);
}
});
setBounds(10,10,450,400);
setVisible(true);
}
class Copy implements Runnable
{
File source,dest;
FileInputStream in ;
FileOutputStream out ;
public Copy(File source,File dest)
{
this.source=source;
this.dest=dest;
try
{
in = new FileInputStream(source);
out = new FileOutputStream(dest);
}
catch (Exception ex)
{
}
//proBar.setMaximum((int)source.length());
}
public void run()
{
int c=0;
int readed=0;
JProgressBar pBar=new JProgressBar(0,100);
JFrame f=new JFrame();
f.setSize(500,50);
f.getContentPane().add(pBar);
f.setVisible(true);
try {
while ((c = in.read()) != -1)
{
out.write(c);
readed++;
int s=(int)(readed*100/source.length());
System.out.println (s);
pBar.setValue(s);
pBar.setStringPainted(true);
}
in.close();
out.close();
}
catch (Exception ex) {
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -