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
|
package installationLogiciels;
import javax.swing.* ;
import java.awt.* ;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL ;
import java.util.* ;
import javax.swing.filechooser.FileSystemView ;
public class VueBoutons extends JPanel {//implements Observer {
private Modele modele ;
private JButton ajouter ;
private JButton enlever ;
private JButton installer ;
private URL imgAjouterURL = VueBoutons.class.getResource("icones/ajouterListe.png");
private URL imgEnleverURL = VueBoutons.class.getResource("icones/enleverListe.png");
private URL imgInstallerURL = VueBoutons.class.getResource("icones/installer.png");
private GridLayout listeBoutons ;
public VueBoutons(Modele modele) {
super();
this.modele = modele ;
listeBoutons = new GridLayout(1,3);
setLayout(listeBoutons);
ajouter = new JButton(new ImageIcon(imgAjouterURL));
enlever = new JButton(new ImageIcon(imgEnleverURL));
installer = new JButton(new ImageIcon(imgInstallerURL));
ajouter.addActionListener(new Charger(modele));
//.......
//enlever.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent e){}
//}
// );
//installer.addActionListener(..
this.add(ajouter);
this.add(enlever);
this.add(installer);
//modele.addObserver(this);
//update(null,null);
}//VueBoutons(Modele)
//public void update(Observable o, Object arg){}
public class Charger implements ActionListener {
private Modele modele ;
public Charger(Modele modele) {
this.modele = modele;
}
public void actionPerformed(ActionEvent e) {
JFileChooser chooser;
try {
chooser = new JFileChooser();
//FileSystemView vueSysteme = FileSystemView.getFileSystemView();
// File la ou on est + definition du repertoir par default
File f = new File(new File("\\\\mercure\\Utilitaires").getCanonicalPath());
chooser.setCurrentDirectory(f);
int returnVal = chooser.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
String nom = chooser.getSelectedFile().getName();
String chemin = chooser.getSelectedFile().getCanonicalPath();
modele.ajouterLogiciels(nom,chemin);
}//if (returnVal
}//try
catch (FileNotFoundException err) { JOptionPane.showMessageDialog(null,err.getMessage(),"erreur",JOptionPane.ERROR_MESSAGE); }
catch (IOException err) { JOptionPane.showMessageDialog(null,err.toString(),"erreur",JOptionPane.ERROR_MESSAGE); }
catch (NumberFormatException err) { JOptionPane.showMessageDialog(null,err.getMessage(),"erreur",JOptionPane.ERROR_MESSAGE); }
}//catch
}
} |
Partager