swingworker


Cannot call a method in swing worker


I have a button with ActionListener and try to call the CopyTask method in SwingWorker but eclipse says an error
"The method CopyTask(File, File) is undefined for the type ActionListener(){}". Can you guys help
//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;
}
Could you refactor your code slightly so that it can be used as an example entirely on its own. I can't really see (from your code example) where the button comes into play right now?
Example :
public class A extends JFrame {
File src;
File dst;
JButton button;
public A() {
// Add button to JFrame
// Set button action
button.setAction(new AbstractAction() {
public void actionPerformed() {
CopyTask ct = new CopyTask(src, dst);
ct.execute();
}
}
}
class CopyTask extends SwingWorker<Void, Integer> { ... }
}

Related Links

ProgressBar and ScheduledExecutorService
Can I modify states of an object in a swing worker thread which has existed before the SwingWorker is instantiated?
Interrupting more SwingWorkers at once
Is it beneficial to use SwingWorker when it has to block the UI?
JProgress Bar not updating
Cannot call a method in swing worker
is SwingWorker.done() guaranteed to execute after the worker's last invocation of SwingWorker.process()?

Categories

HOME
search
localization
time-complexity
jmx
3d
apache-spark-mllib
requirements
owl-carousel
pdfbox
edge
regular-language
code-coverage
nfs
elasticsearch-5
mql5
openpyxl
ycsb
comsol
standards
imessage
jmp
enterprise-miner
question2answer
oculus
apktool
google-earth
autolisp
dsx-desktop
twos-complement
keras-layer
reason
alphabetical
lint
bc
numberpicker
print-css
oracle-service-bus
bindingnavigator
knime
dapper-simplecrud
flask-restful
openresty
reportservice2010
dtsearch
manova
stdmap
compiler-design
filehandle
avx
flyout
node-request
pytables
mapxtreme
wso2developerstudio
android-dateutils
vorpal.js
jclouds
nss
kiosk
false-sharing
realsense
opl
ess
flock
coda
baasbox
ocra
avahi
snackbar
matlab-deployment
entity-framework-4.3
rickshaw
extjs2
multitasking
scrypt
jeromq
twisted.web
wimax
ilasm
update-statement
tmx
zend-rest
duplex
lalr
cldc
wysiwym
fdf
java1.4

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App