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
azure-stream-analytics
porting
twitter-bootstrap-3
awk
c++11
time-complexity
alexa-skills-kit
spring-data-mongodb
google-apps
azure-container-service
webix
redis-sentinel
automatic-ref-counting
cumulocity
gruntfile
job-scheduling
android-7.0-nougat
apache2.4
solrcloud
selinux
dpdk
short-url
jquery-callback
froala
windows-server-2003
xcode-ui-testing
tiki-wiki
onload
custom-post-type
nstimer
inversion-of-control
nsurl
dst
sql-server-2000
android-gridview
classcastexception
sim-toolkit
timing
release
azure-arm
placeholder
show-hide
opencmis
term
hammer.js
dtsearch
truezip
dt
bbpress
type-theory
flyout
cmp
gameplay-kit
jtree
pocketsphinx-android
docpad
pure-css
jodd
drawstring
tooleap
swizzling
freepbx
turbo-prolog
kendo-upload
lazybones
toolkit
branch-and-bound
typeconverter
android-broadcast
nodelist
nsmenu
unix-socket
lambda-architecture
cuba
live555
malformedurlexception
buffering
android-framework
multitasking
android-usb
cocoalibspotify-2.0
gpars
flex++
scmmanager
onload-event
veracity
pyunit
boost-signals
multiplexing
httponly
floating-point-exceptions
cgimage
jquery-tools
htdocs
pylucene
office-2007
hbm2java
tabpanel
strtod
wcf-instancing
application-planning
great-circle

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