public void calcul(){ /* tout plein de code ^^ */ }
public void calcul() { new Thread(new Runnable() { public void run(){ /* tout plein de code ^^ */ } }).start(); }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionpublic class MyProgressMonitor // ... // ... public static void main(String[] args) { new MyProgressMonitor(null,false); } // ... }
public class MyProgressMonitor extends JFrame implements ChangeListener{ private static final long serialVersionUID = 1L; private JProgressBar current; private Dimension screenSize; private int windowX; private Dimension windowSize; private int windowY; private static JButton but; private JPanel pane; public MyProgressMonitor(JButton button, boolean b) { super("Progression"); setBackground(Color.white); setLocationRelativeTo(null); screenSize = Toolkit.getDefaultToolkit().getScreenSize(); windowSize = getSize(); windowX = Math.max(0, (screenSize.width - windowSize.width) / 3); windowY = Math.max(0, (screenSize.height - windowSize.height) / 2); if(button != null){ but = button; but.setEnabled(b); } pane = new JPanel(); pane.setLayout(new FlowLayout()); current = new JProgressBar(0, 99); current.setValue(0); current.setString ("Progession: " + (int)(current.getPercentComplete()*100) + "%"); current.setStringPainted(true); current.addChangeListener(this); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); pane.add(current); setVisible(true); setSize(new Dimension(250,75)); setResizable(false); setLocation(windowX, windowY); setContentPane(pane); } public void remove(JButton butt) { setVisible(false); current = null; pane = null; butt.setEnabled(true); } public void setProgress(int num){ current.setValue(num); current.setString ("Progession: " + (int)(current.getPercentComplete()*100) + "%"); } @Override public void stateChanged(ChangeEvent arg0) { current.setString ("Progession: " + (int)(current.getPercentComplete()*100) + "%"); } }
final MyProgressMonitor prog = new MyProgressMonitor(button,false); new Thread(new Runnable() { public void run(){ /* tout plein de code :) (interaction avec bdd...) */ } }).start();