IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Concurrence et multi-thread Java Discussion :

Thread, reprendre la main après un sleep


Sujet :

Concurrence et multi-thread Java

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Invité1
    Invité(e)
    Par défaut 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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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);
    	}
    }
    Dernière modification par Invité1 ; 04/04/2008 à 22h28.

Discussions similaires

  1. [WD12] Reprendre la main après LanceAppliAssociée
    Par Lo² dans le forum WinDev
    Réponses: 2
    Dernier message: 01/03/2010, 13h59
  2. Reprendre la main avec SAS après une utilisation de Matlab
    Par 8twilight8 dans le forum SAS Base
    Réponses: 5
    Dernier message: 03/03/2009, 11h21
  3. thread perd la main entre 2 sleep()
    Par Nicool dans le forum Concurrence et multi-thread
    Réponses: 11
    Dernier message: 29/10/2007, 09h06
  4. [DOS] Reprendre la main après le lancement d'un programme
    Par kimz dans le forum Scripts/Batch
    Réponses: 9
    Dernier message: 28/05/2007, 23h58
  5. Vider le buffer après un sleep ?
    Par olivier857 dans le forum C
    Réponses: 7
    Dernier message: 28/03/2006, 15h00

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo