I have a scenario where I need my swing UI to run on two different threads. I have a laptop where I will my application will run. There is a Button on clicking which an presentation should start at the other Screen that is attached to my laptop.
Now I have made a class presentation which is extending SwingWorker and reads the images from a folder and displays it on screen.
class Presenatation extends SwingWorker<Integer, Integer> {
@Override
protected Integer doInBackground() throws Exception {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
start(outputFolder, screenVO);/*Creates a JFrame to be displayed
on new screen and sets a JPanel to it. Reads the file images sets it into
JLabels every 2 seconds and updates it to Japnel*/
}
});
return null;
}
Inside my start method I have the code to read images and show them on the UI
What I feel is this approach is wrong since my SwingWorker shouldn't be calling invokeLater in doInBackground()
From what little knowledge I have, it should be something like this:
@Override
protected Void doInBackground() throws Exception
{
return null;
}
@Override
protected void process(List<Integer> chunks
{
}
I am not able to decide which part should be placed where ?
I have the following things to do :
- Start a new Frame to be displayed on a new screen
- Load Images into the frame every 2 seconds reading the image from a folder
- Extending Presentation class to SwingWorker, is this approach Correct ? Because externally I have an Executor object in whose exec() I am passing the object of Presentation
Please help me !