How to set up the following structure, in order to meet the requirements of SwingWorker (doInBackground, publish, process):
1. There is a class SGui - contained in a package of Swing GUI methods SGui, located in package ...sgui - which will
- start a background thread, by using SwingWorker, which does some complex logics (the methods from class SSolv, see item 2)
- it passes initial data to that background process, which have been entered into the GUI
- displays the intermediate results from the background threat
2. There is another class SSolv, in package ...ssolv, which contains some complex logics, and should deliver intermediate results to be displayed by the GUI
From all the information from tutorial etc., I put up a structure like this, for SSolv:
package ...ssolv;
class SSolv {
......
void senderMethod {
:
publish (ComData...) // should transfer the data to the EDT
:
.. }
: class ComData {
// ... puts up the objects for transferring the data to the GUI, by method publish
}
}
All the rest of Swing methods goes to package SGui.
This stub already shows the issue, which comes from structuring the application in two (or even more) packages : compiling package SSolv produces the error
publish(V...)
has protected access in javax.swing.SwingWorker ! I understand that this protected method could only be used in this context, after instancing a subclass of SwingWorker,
- however I thought it would most senseful to get the "sender" (+publish+), and the "contents" (+ComData+) to the package, where the data will be produced.
This is evidently in contradiction to the requirement, that
publish - as a protected method of
SwingWorker - should be defined in the SGui class, as it has to apply the (overriden) methods
process (including get),
done etc.
With my application, the SGui class will be compiled later ! So I had to reference a method from SGui that is not known during compiling of SSolv !
Unfortunately, all the examples shown in the tutorials (as far as I can already know them...) only use one package; so all the classes are compiled from one file, and they will not get this dilemma.
Please give me some idea, how I will have to restructure / workaround / use advanced methods, to solve this ?
Edited by: GW.G on 16.07.2010 17:27