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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
package seriousJob;
import java.awt.FlowLayout;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class ModificateurDeFichier extends JFrame {
private JFrame frame;
private JPanel pan;
private JButton modif;
private JButton view;
private JTextArea textA;
private JPanel pan2;
private JTextField textF;
private JLabel lab1;
public ModificateurDeFichier() {
// Initialisation
frame = new JFrame();
frame.setSize(500, 500);
frame.setLayout(new FlowLayout());
pan = new JPanel();
pan2 = new JPanel();
modif = new JButton("Modification");
view = new JButton("Apercu");
textA = new JTextArea(25, 25);
textF = new JTextField(10);
lab1 = new JLabel("Nom fichier");
view.addActionListener(new viewTheThing());
modif.addActionListener(new editTheThing());
pan.add(lab1);
pan.add(textF);
pan.add(view);
pan.add(modif);
pan2.add(textA);
frame.add(pan);
frame.add(pan2);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setVisible(true);
}
private class viewTheThing implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
String depot = "";
String input1 = textF.getText();
try {
FileInputStream fstream = new FileInputStream(input1);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(
new InputStreamReader(in));
String strLine;
// Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
// textA.setText(strLine);
depot = strLine + "\n" + depot;
textA.setText(depot);
}
} catch (FileNotFoundException ex) {
System.out.println("Erreur, fichier introuvable");
} catch (IOException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
}
}
private class editTheThing implements ActionListener {
String input1 = textF.getText();
@Override
public void actionPerformed(ActionEvent e) {
try {
//quoi faire!!!
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
}
}
} |
Partager