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
|
try {
String nom = System.getProperty("user.name");
String line = null;
String path = "memoire.txt";
String line2 = null;
String path2 = "connaissances.txt";
String base = null;
String user = jTextArea1.getText();
String prompt = nom + " : " + user;
String histo = jEditorPane1.getText();
jEditorPane1.setContentType("text/html");
jEditorPane1.setEditable(false);
String bot = jTextArea1.getText().toUpperCase();
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument doc = new HTMLDocument();
jEditorPane1.setEditorKit(kit);
jEditorPane1.setDocument(doc);
int rech = 0;
int rep = bot.length();
Scanner scanner = new Scanner(new File(path2));
while (scanner.hasNextLine()) {
line2 = scanner.nextLine();
if (bot.contains(line2)) {
base = scanner.nextLine();
rech = 4;
}
else if (line2.contains(" DATE ")) {
rech = 1;
}
else if (line2.contains(" HEURE ")) {
rech = 2;
}
else if (rep < 2) {
rech = 5;
}
else {
kit.insertHTML(doc, doc.getLength(), histo + "<br>", 0, 0, null);
kit.insertHTML(doc, doc.getLength(), prompt + "<br>", 0, 0, null);
kit.insertHTML(doc, doc.getLength(), "Je ne comprends pas<br>", 0, 0, null);
jTextArea1.setText("");
}
}
scanner.close();
switch (rech) {
// date
case 1:
Date time = new Date();
DateFormat dfl = DateFormat.getDateInstance(DateFormat.FULL);
kit.insertHTML(doc, doc.getLength(), histo + "<br>", 0, 0, null);
kit.insertHTML(doc, doc.getLength(), prompt + "<br>", 0, 0, null);
kit.insertHTML(doc, doc.getLength(), "Prof Tux : Nous sommes le " + dfl.format(time) + "<br>", 0, 0, null);
jTextArea1.setText("");
break;
case 2:
Date date = new Date();
SimpleDateFormat dateFormatComp;
dateFormatComp = new SimpleDateFormat("dd MMM yyyy hh:mm:ss a");
kit.insertHTML(doc, doc.getLength(), histo + "<br>", 0, 0, null);
kit.insertHTML(doc, doc.getLength(), prompt + "<br>", 0, 0, null);
kit.insertHTML(doc, doc.getLength(), "Prof Tux : " + dateFormatComp.format(date), 0, 0, null);
jTextArea1.setText("");
break;
// en mémoire
case 3:
kit.insertHTML(doc, doc.getLength(), histo + "<br>", 0, 0, null);
kit.insertHTML(doc, doc.getLength(), prompt + "<br>", 0, 0, null);
kit.insertHTML(doc, doc.getLength(), "Prof Tux : On en a déja parlé il me semble" + "<br>", 0, 0, null);
jTextArea1.setText("");
break;
// base
case 4:
kit.insertHTML(doc, doc.getLength(), histo + "<br>", 0, 0, null);
kit.insertHTML(doc, doc.getLength(), prompt + "<br>", 0, 0, null);
kit.insertHTML(doc, doc.getLength(), base + "<br>", 0, 0, null);
jTextArea1.setText("");
break;
// réponse vide
case 5:
kit.insertHTML(doc, doc.getLength(), histo + "<br>", 0, 0, null);
kit.insertHTML(doc, doc.getLength(), prompt + "<br>", 0, 0, null);
kit.insertHTML(doc, doc.getLength(), "Prof Tux : Vous n'avez rien à dire" + "<br>", 0, 0, null);
jTextArea1.setText("");
break;
} |
Partager