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
|
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class FenetreManager extends JFrame{
public FenetreManager(){
super();
build();
}
private JFileChooser choixSource = new JFileChooser();
private JTextField champSource = new JTextField();
private JButton parcourSource = new JButton("...");
private JFileChooser choixDesti = new JFileChooser();
private JTextField champDesti = new JTextField();
private JButton parcourDesti = new JButton("...");
private JButton demarrerCopie = new JButton("Démarrer la copie");
private void build(){
String fichierSourceDefaut = "SourceDefaut.txt";
String adresseSourceDefaut = "";
try{
InputStream ips=new FileInputStream(fichierSourceDefaut);
InputStreamReader ipsr=new InputStreamReader(ips);
BufferedReader br=new BufferedReader(ipsr);
adresseSourceDefaut=br.readLine();
br.close();
}
catch (Exception e){
}
champSource.setText(adresseSourceDefaut);
setTitle("Aero Challenge");
setSize(400,120);
setLocationRelativeTo(null);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel fenetreLabels = new JPanel(new GridLayout(2, 1, 5, 5));
fenetreLabels.add(new JLabel("Source :"));
fenetreLabels.add(new JLabel("Destination :"));
JPanel fenetreChoix = new JPanel(new GridLayout(2, 1, 5, 5));
fenetreChoix.add(this.champSource);
fenetreChoix.add(this.champDesti);
JPanel fenetreDemarrer = new JPanel(new GridLayout(1, 1, 5, 5));
fenetreDemarrer.add(this.demarrerCopie);
demarrerCopie.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ev){
JOptionPane.showMessageDialog(null, "Copie en cours");
}
});
JPanel fenetreParcour = new JPanel(new GridLayout(2, 1, 5, 5));
fenetreParcour.add(this.parcourSource);
parcourSource.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ev){
JFileChooser chooser = new JFileChooser();
chooser.setApproveButtonText("Valider");
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION){
champSource.setText(chooser.getSelectedFile().getAbsolutePath());
}
}
});
fenetreParcour.add(this.parcourDesti);
parcourDesti.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ev){
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File("/"));
chooser.changeToParentDirectory();
chooser.setApproveButtonText("Valider");
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION){
champDesti.setText(chooser.getSelectedFile().getAbsolutePath());
}
}
});
setLayout(new BorderLayout(10, 10));
add (fenetreLabels, BorderLayout.WEST);
add (fenetreChoix, BorderLayout.CENTER);
add (fenetreParcour, BorderLayout.EAST);
add (fenetreDemarrer, BorderLayout.SOUTH);
}
} |
Partager