Bonjour le forum,


j'ai un problème, j'ai créée un composant graphique qui contient un bouton et un textfield et filechooser.

Alors mon problème est que j'ai un seule bouton mais il doit soit ouvrir (filechooser) ou soit enregistrer, mais je ne sais pas comment faire, car à chaque fois j'ai deux boutons qui s'affichent mais les deux font la même action...

Je ne sais pas si je m'explique bien.... voici un peu du code...:
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
 
//Déclaration du buton
nomButton=new JButton("Open");
nomButton=new JButton("Save");
 
//Ajoute du bouton
this.add(nomButton);
 
//Ajoute evenement
nomButton.addActionListener(this);
nomButton.addPropertyChangeListener(this);
 
public void actionPerformed(ActionEvent evt) {	
		Object source= evt.getSource();
		Boolean status=false;
		String nom= nomButton.getText().toString();
 
 
			if(source==nomButton){
				if(nom=="Open"){
				 returnVal = choixFichier.showOpenDialog(Composant_graph.this);       
		          if (returnVal == JFileChooser.APPROVE_OPTION){
		              File file = choixFichier.getSelectedFile();		              
		              fileinField.setText(file.getPath());
		          }
		        /*  if(!status)
		          {
		        	  JOptionPane.showMessageDialog (null, "Error opening file!", "File Open Error",JOptionPane.ERROR_MESSAGE); 
		          }*/
 
			}else if(source==nomButton)
				{
				if(nom=="Save"){
				  returnVal = choixFichier.showSaveDialog(Composant_graph.this);  
					if (returnVal == JFileChooser.APPROVE_OPTION){
			            File file = choixFichier.getSelectedFile();
			            if(!file.getName().endsWith(".xls")){
			            	   file = new File(file.getParentFile(),file.getName()+".xls");
			               }		               
			               fileinField.setText(file.getPath());			               
			           }
				}
				}
 
 
			}
	}

apres dans ma classe qui contient le main, je fais la creation du frame et je fais l'appel de mon bouton....

Au debut je lui passé en parametre le nom du bouton mais on m'a dit de déclarer le type(ovrir, enregistrer) separement......

voilà merci à tous pour votre aide!