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());
}
}
}
}
} |
Partager