public void init_compo(){
lbl1=new JLabel("Source");
lbl1.setBounds(20, 10, 100, 25);
add(lbl1);
lbl2=new JLabel("Destination");
lbl2.setBounds(20, 40, 100, 25);
add(lbl2);
tfSource=new JTextField("c:/source");
tfSource.setBounds(120, 10, 250, 25);
add(tfSource);
tfDestination=new JTextField("c:/dest");
tfDestination.setBounds(120, 40, 250, 25);
add(tfDestination);
btnopen=new JButton("...");
btnopen.setBounds(370, 10,50, 25);
btnopen.setActionCommand("OPEN");
btnopen.addActionListener(this);
add(btnopen);
btncopier=new JButton("Copier");
btncopier.setBounds(20, 80,80, 25);
btncopier.setActionCommand("COPIER");
btncopier.addActionListener(this);
add(btncopier);
lbfin=new JLabel();
lbfin.setBounds(120, 80, 100, 25);
add(lbfin);
}
public void copier(String source, String destination){
try{
fis=new FileInputStream(source);
}
catch(IOException ioe){
System.out.println("Ficier source inexistant");
System.exit(200);
}
try {
fos=new FileOutputStream(destination);
lbfin.setText("Début de la copie");
while(fis.available()>0){
fos.write(fis.read());
}
fos.close();
fis.close();
lbfin.setText("Copie Terminée");
} catch(IOException ioe){
System.out.println("Imposible de creer le fichier destination");
System.exit(150);
}
}
5/34