allora, nell'actionPerformed richiamo questo metodo:
nello swing worker:codice:private void createConnection() { try { if (CheckConnection.check()) { JDialog jd = new JDialog(this, true); jd.add(BorderLayout.CENTER, new JLabel("...LOADING...")); jd.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); jd.setSize(300, 75); jd.setResizable(false); jd.setLocationRelativeTo(this); LoadingDialog ld = new LoadingDialog(jd); ld.execute(); } else { JOptionPane.showMessageDialog(null, "No connection"); } } catch (IOException ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); } }
così mi pare che vada.codice:public class ServiceWorker extends SwingWorker<Object, Object> { private Service jsb; private JDialog jd; public ServiceWorker(JDialog jd) { jsb = new Service(); this.jd = jd; } @Override protected Object doInBackground() throws Exception { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { jd.setVisible(true); try { jsb.launchService("all_books"); jsb.launchService("all_authors"); jsb.launchService("all_editors"); jsb.download(UrlAndPath.JSON_LIBRI); jsb.download(UrlAndPath.JSON_AUTORI); jsb.download(UrlAndPath.JSON_EDITORI); jsb.download(UrlAndPath.GRAPH_AUTHORS); } catch (IOException ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); } } }); return null; } @Override protected void done() { jd.setVisible(false); } }
dal punto di vista logico invece, andrebbe bene??

Rispondi quotando

