我有一个带有 ActionListener 的按钮,并尝试在 SwingWorker 中调用 CopyTask 方法,但 Eclipse 显示错误“对于 ActionListener(){} 类型的方法 CopyTask(File, File) 未定义”。你们能帮忙吗
//imported everything needed
public class A extends JFrame implements PropertyChangeListener
{
File src;
File dest;
CopyTask task;
//other components
JTextFiles jt = new JTextField();
src = new File(jt.getText()); //getting input from JTextField
dest = new File ("\\C$\\Web"); //providing the location manually
CopyTask task = this.new CopyTask(src, dest);
task.addPropertyChangeListener(this);
task.execute();
@Override
public void propertyChange(PropertyChangeEvent evt)
{
if("progress".equals(evt.getPropertyName()))
{
int progress = (Integer) evt.getNewValue();
progressAll.setValue(progress);
}
}
class CopyTask extends SwingWorker<Void, Integer>
{
private File source;
private File target;
private long totalBytes = 0;
private long copiedBytes = 0;
public CopyTask(File src, File dest)
{
this.source = src;
this.target = dest;
progressAll.setValue(0);
// progressCurrent.setValue(0);
}
@Override
public Void doInBackground() throws Exception
{
ta.append("Retrieving some info ... ");
retrieveTotalBytes(source);
ta.append("Done!\n");
copyFiles(source, target);
return null;
}