Thread, reprendre la main après un sleep
Bonjour bonjour,
Voici mon problème dans mon main je lance une autre classe pour l'interface graphique et suivant les boutons cochés part l'utilisateur j'aimerai continuer mon main et faire des actions en fonction de ces boutons cochés ou non.
Le problème c'est que mon main lui il ne m'attend pas pour continuer!
J'ai essayer de faire un sleep dans le main après l'exécution de l'interface graphique et de relancer le main après avoir appuyé sur le bouton OK mais j'ai une exception.
S'il y a d'autres possibilités que ma soupe à l'onion je suis preneur!
Merci.
Le main:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
public class Main {
public static Thread get_Thread (){
return Thread.currentThread();
}
public static void main(String[] args) {
try {
Launch program = new Launch();
program.setVisible(true);
Thread.currentThread().suspend();
if (program.get_Manager() == true)
System.out.println("Managerok");
if (program.get_Fireman() == true)
System.out.println("Firemanok");
if (program.get_Policeman() == true)
System.out.println("Policemanok");
} catch (Throwable all) {
// Something bad happened, print out the failure and quit.
System.err.println("Uncaught Throwable in main() :");
all.printStackTrace(System.err);
System.exit(1);
}
}
} |
Et voici l'interface:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
public class Launch extends JFrame {
String adressicon = System.getProperty("user.dir")
+ File.separator + "src" + File.separator + "app" + File.separator
+ "GUI";
boolean done = false;
JButton ok = new JButton("OK");
JCheckBox manager_check = new JCheckBox();
JCheckBox fireman_check = new JCheckBox();
JCheckBox policeman_check = new JCheckBox();
public Launch(){
super();
build();//Window initialization
}
public class FirstPanel extends JPanel {
public FirstPanel(String title) {
super(new GridLayout(3, 1));
setBorder(BorderFactory.createTitledBorder(title));
JPanel manager = new JPanel();
manager_check.setSelected(true);
manager.add(manager_check);
JLabel manager_label = new JLabel ("Manager");
Icon manager_Icon = new ImageIcon(adressicon + File.separator + "manager.png");
manager_label.setIcon(manager_Icon);
manager.add(manager_label);
manager.setLayout (new FlowLayout(FlowLayout.LEFT));
add(manager);
JPanel fireman = new JPanel();
fireman.add(fireman_check);
JLabel fireman_label = new JLabel ("Fireman");
Icon fireman_Icon = new ImageIcon(adressicon + File.separator + "fireman.png");
fireman_label.setIcon(fireman_Icon);
fireman.add(fireman_label);
fireman.setLayout (new FlowLayout(FlowLayout.LEFT));
add(fireman);
JPanel policeman = new JPanel();
policeman.add(policeman_check);
JLabel policeman_label = new JLabel ("Policeman");
Icon policeman_Icon = new ImageIcon(adressicon + File.separator + "policeman.png");
policeman_label.setIcon(policeman_Icon);
policeman.add(policeman_label);
policeman.setLayout (new FlowLayout(FlowLayout.LEFT));
add(policeman);
}
}
public boolean get_Manager () {
return manager_check.isSelected();
}
public boolean get_Fireman () {
return fireman_check.isSelected();
}
public boolean get_Policeman () {
return policeman_check.isSelected();
}
private void build(){
setTitle("CriSafe v1.0");
setSize(150,300);
setLocationRelativeTo(null);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout (new GridLayout(2, 1));
JPanel panel = new JPanel();
panel.setLayout (new FlowLayout(FlowLayout.LEFT));
panel.add(new FirstPanel("Choose your role(s)"));
add (panel);
ok.addActionListener ( new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(false);
Main.get_Thread().resume();
}
});
add (ok);
}
} |
OK voici plus d'explication!
En gros ce que je veux c'est que mon main attende que j'ai cliqué sur le bouton OK de l'interface graphique pour continuer.
Et aussi il faut que l'interface graphique et le main ne soient pas dans la même classe.
Merci encore pour ton aide.