Bonjour,
Je suis étudiant et comme la majorité des étudiants j'ai un projet a finaliser.
Je dois effectuer un programme qui soit capable de faire de la recherche en parallèle.
Je debute en java et mon probleme est au niveau de la gestion des évenements.
Dans mon programme, j'ai une petite fenetre qui pour l'instant doit permettre d'entrer deux nom et de faire la recherche grace à deux threads.
Pour ma recherche ca à l'air de fonctionner pour l'instant meme si elle reste a optimisé mais j'ai du mal avec la gestion des evenements.

Mes deux JTextField s'affiche et je peux y tapé du texte mais dès que je passe la souris dans la fenetre je n'ai plus accès au TextField et quand je clique sur mon bouton on dirait que mon programme se fige plus rien .

Je vous laisse donc le code qui concerne que la partie graphique.

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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
 import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ContainerListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import Recherche.RechercheDocument;
 
import javax.swing.*;
 
public class FenetreRecherche extends JFrame{
 
	private static final long serialVersionUID = 1L;
	private static final int LEFT = 0;
	//private FenetreEcouteur ecoutefen;
	private JPanel panelHaut,panelCentre,panelBas;
	private JLabel labRecherche;
	private JLabel fichierEnCours;
	private JLabel fichierEnCours2;
	private JTextField recherche;
	private JTextField recherche2;
	private JButton boutonRecherche;
 
	private JRadioButton texte;
	private JRadioButton image;
	private JRadioButton binaire;
	private JRadioButton executable;
 
	//private JRadioButton 
	public FenetreRecherche(){
		build();
	}
	public void build()
	{
		this.setTitle("Miagle");
		this.setLayout(new GridLayout(3,1,1,1));
		panelHaut=new JPanel();
		panelCentre=new JPanel();
		panelBas=new JPanel();
 
		/* affichage panelHaut*/
		panelHaut.setLayout(new FlowLayout());
		labRecherche =new JLabel("Recherche :");
		recherche=new JTextField(20);
		recherche2=new JTextField(20);
		boutonRecherche=new JButton("valider");
 
		panelHaut.add(labRecherche);
		panelHaut.add(recherche);
		panelHaut.add(recherche2);
		panelHaut.add(boutonRecherche);
 
		/*affichage panelCentre*/
		panelCentre.setLayout(new GridLayout(3,3,1,1));
		texte=new JRadioButton("fichier texte");
		image=new JRadioButton("fichier image");
		binaire=new JRadioButton("fichier binaire");
		executable=new JRadioButton("fichier executable");
		panelCentre.add(texte);
		panelCentre.add(image);
		panelCentre.add(binaire);
		panelCentre.add(executable);
 
		/*affichage panelBas*/
		panelBas.setLayout(new GridLayout(2,2,1,1));
		fichierEnCours=new JLabel("Resultat");
		panelBas.add(fichierEnCours);
		fichierEnCours2=new JLabel("Resultat");
		panelBas.add(fichierEnCours2);
 
 
		/*affichage des panel*/
		this.add(panelHaut);
		this.add(panelCentre);
		this.add(panelBas);
 
		/*ajout des ecouteur*/
 
		boutonRecherche.addActionListener(new boutonRechercheListener());
		recherche.addActionListener(new rechercheListener());
		this.setSize(600, 600);
		this.setVisible(true);
 
	}	
	class rechercheListener implements ActionListener{
 
		public void actionPerformed(ActionEvent arg0){
			System.out.println("ecriture dans le textfield 1");
		}
	}
	class boutonRechercheListener implements ActionListener{
 
        /**
         * Redéfinition de la méthode actionPerformed
         */
        public void actionPerformed(ActionEvent arg0) {
        	RechercheDocument fich=new RechercheDocument(recherche.getText());
			RechercheDocument fich2=new RechercheDocument(recherche2.getText());
 
			fich.start();
			fich2.start();
			System.out.println(fich.getResultat());
			System.out.println(fich2.getResultat());
			fichierEnCours.setText(fich.getResultat());
			fichierEnCours2.setText(fich2.getResultat());
               }
	}
}
cordialement.