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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
package projet;
import java.io.*;
import java.util.*;
import java.util.List;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* <p>Titre : </p>
* <p>Description : Soumia Benmostefa </p>
* <p>Copyright : Copyright (c) 2008</p>
* <p>Société : </p>
* @author non attribuable
* @version 1.0
*/
public class Analyseur extends JFrame {
JPanel jPanel1 = new JPanel();
JScrollPane jScrollPane1 = new JScrollPane();
JTextArea jTextArea1 = new JTextArea();
JButton jButton1 = new JButton();
public Analyseur() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Analyseur analyseur = new Analyseur();
analyseur.setSize(800,600);
analyseur.setVisible(true);
}
private void jbInit() throws Exception {
this.getContentPane().setBackground(SystemColor.menu);
this.getContentPane().setLayout(null);
jPanel1.setBackground(SystemColor.menu);
jPanel1.setBounds(new Rectangle(14, 13, 380, 279));
jPanel1.setLayout(null);
jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jScrollPane1.getViewport().setBackground(Color.white);
jScrollPane1.setForeground(Color.black);
jScrollPane1.setBounds(new Rectangle(38, 5, 342, 183));
jTextArea1.setText("si ciel=couvert et vent=fort alors jouer=non");
jButton1.setBackground(Color.white);
jButton1.setBounds(new Rectangle(98, 194, 152, 39));
jButton1.setText("Lancer L\'analyse");
jButton1.addActionListener(new Analyseur_jButton1_actionAdapter(this));
this.getContentPane().add(jPanel1, null);
jPanel1.add(jScrollPane1, null);
jPanel1.add(jButton1, null);
jScrollPane1.getViewport().add(jTextArea1, null);
}
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void jButton1_actionPerformed(ActionEvent e) {
try {
CreerFichier(jTextArea1.getText());
BufferedReader buffer= new BufferedReader(new FileReader("C:\\BaseDesRègles.txt"));
while (buffer.ready()) {
Analyser(buffer.readLine());
}
}
catch (IOException ex) {
ex.printStackTrace();
}
}
private void CreerFichier(String str) {
try {
File F = new File("C:\\BaseDesRègles.txt");
BufferedWriter buffWrit = new BufferedWriter(new FileWriter(F));
buffWrit.write(str);
buffWrit.flush();
buffWrit.close();
}
catch (IOException ex) {
ex.printStackTrace();
}
}
void Analyser(String str) {
List RulsCondion = new ArrayList();
List RulsResult = new ArrayList();
StringTokenizer tokenizer = new StringTokenizer(str);
String Token = tokenizer.nextToken();
//StreamTokenizer StrTokenizer ;
StringBuffer iput;
if (Token.equalsIgnoreCase("si")) {
Token = tokenizer.nextToken();
while ( (tokenizer.hasMoreTokens()) && (!Token.equalsIgnoreCase("alors"))) {
iput = new StringBuffer();
while ( (!Token.equalsIgnoreCase("et")) &&
(!Token.equalsIgnoreCase("alors"))) {
iput.append(Token);
Token = tokenizer.nextToken();
}
RulsCondion.add(iput.toString());
}
iput = new StringBuffer(Token);
while (tokenizer.hasMoreTokens()) {
iput.append(tokenizer.nextToken());
}
RulsResult.add(iput.toString());
}
for (Iterator _RulsCondion = RulsCondion.iterator(); _RulsCondion.hasNext(); ) {
System.out.println(_RulsCondion.next());
}
System.out.println("----------------------------------");
for (Iterator _RulsResult = RulsResult.iterator(); _RulsResult.hasNext(); ) {
System.out.println(_RulsResult.next());
}
}
}
class Analyseur_jButton1_actionAdapter implements java.awt.event.ActionListener {
Analyseur adaptee;
Analyseur_jButton1_actionAdapter(Analyseur adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
} |
Partager