The following example fetches Facebook data in a background process and passes the data to the GUI.

SwingWorker<User, String> fetchUserWorker = new SwingWorker<User, String>()
{
@Override
protected User doInBackground() throws Exception
{
IFacebookController controller = new RestFBController(accessToken);

User user = controller.fetchMe();

return user;
}

@Override
protected void done()
{
User user;
try
{
BackgroundProcess.this.mainGui.appendProgressLog("Fetched user record");

// get the user object from doInBackground()
user = get();
mainGui.setCurrentUser(user);
}
catch (InterruptedException | ExecutionException e)
{
BackgroundProcess.this.mainGui.appendProgressLog("ERROR fetching facebook data "+e.getMessage());
e.printStackTrace();
}

}
};

BackgroundProcess.this.mainGui.appendProgressLog("Fetch Current User - Connecting to Facebook");

fetchUserWorker.execute();

Leave a comment

Skills421

Welcome to Skills421, our knowledge repository for all things tech in the 21st century

Let’s connect

Search