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
| package Commentaire;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
import java.util.regex.Pattern;
import javax.swing.ButtonGroup;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
public class Essay extends JFrame implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
JList list ;
DefaultListModel model;
final JButton A ;
JPanel panel ;
JScrollPane P ;
JCheckBox chek ;
public Essay() {
setSize(new Dimension(1000, 1000));
list = new JList();
list.setSize(new Dimension(700, 700));
model = new DefaultListModel();
panel = new JPanel() ;
P = new JScrollPane() ;
A = new JButton("Afficher");
int i ;
A.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
try {
String filePath1 = "C:\\Users\\alaa.fezzani\\Desktop\\A.txt";
String line;
String data="blabla";
BufferedReader bf = new BufferedReader(new FileReader(filePath1));
try {
while ( (line = bf.readLine()) != null ) {
data += line;
}
String [] mesCommentaires = data.split("(/\\*)|(\\*/)");
for(int i = 1; i < mesCommentaires.length; i+=2){
System.out.println(mesCommentaires[i]);
list.setModel(model) ;
model.addElement(mesCommentaires[i]) ;
// chek = new JCheckBox() ;
// list.add(chek) ;
// panel.add(chek);
// chek.setVisible(true);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
P.getViewport().setView(list);
P.setPreferredSize(new Dimension(500, 500));
P.createVerticalScrollBar() ;
panel.add(A) ;
panel.add(P);
getContentPane().add(panel);
setVisible(true);
}
public static void main(String[] args) {
new Essay();
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
}
} |
Partager