Fields correctly works and maximum axiome number is set to 1

This commit is contained in:
Arthur 2021-02-17 11:04:12 +01:00
parent 2c52427f88
commit 2b19f4a8be
3 changed files with 23 additions and 38 deletions

View File

@ -82,19 +82,16 @@ public class MainFrame extends JFrame {
public void closeTab() {
//TODO : Pour fermer un onglet, nécessite l'implémentation d'un button fermer grâce à la méthode newTab().
}
public void changeList(String stringToAdd, byte messageType, JTextArea list) {
if (stringToAdd == null) {
switch(messageType) {
case 0:
list.setText("Axiome : \n");
case 1:
list.setText("Règles : \n");
default:
throw new IllegalArgumentException("Wrong argument given to method changeList");
}
}else{
public void changeList(String stringToAdd, JTextArea list,int nbAxioms) {
if(nbAxioms>0)
JOptionPane.showMessageDialog(null, "Nombre maximal d'axiomes créés");
else {
list.append(stringToAdd);
if (stringToAdd == ";")
nbAxioms++;
}
}
public String getAxiom(){
String str = "";
@ -106,19 +103,5 @@ public class MainFrame extends JFrame {
//TODO return the rules
return list;
}
public void incorrect() {
JFrame alert = new JFrame();
alert.setTitle("Erreur");
alert.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
alert.setSize(60,40);
alert.setLocationRelativeTo(null);
JLabel text = new JLabel("Vos règles ou votre axiome ne sont pas correctement écrites, veuillez recommencer");
alert.add(text);
alert.setVisible(true);
changeList(null,(byte) 0,null);
changeList(null,(byte)1,null);
}
}

View File

@ -11,30 +11,31 @@ public class FieldListener implements KeyListener {
MainFrame frame;
int index;
byte i;
int nbAxioms;
byte type;
public FieldListener(MainFrame frame, int index, byte i){
public FieldListener(MainFrame frame, int index,byte type){
this.frame = frame;
this.index = index;
this.i = i;
nbAxioms = 0;
this.type = type;
}
@Override
public void keyTyped(KeyEvent ke) {
if(ke.getKeyCode() != KeyEvent.VK_ENTER)
frame.changeList(String.valueOf(ke.getKeyChar()),i, (JTextArea) frame.textAreaList.get(index));
else{
String str = ";\r\n";
frame.changeList(str,i, (JTextArea) frame.textAreaList.get(index));
frame.textFieldList.get(index).setText(null);
}
if(ke.getKeyCode() != KeyEvent.VK_ENTER && nbAxioms==0)
frame.changeList(String.valueOf(ke.getKeyChar()), (JTextArea) frame.textAreaList.get(index),nbAxioms);
}
@Override
public void keyPressed(KeyEvent ke) {
if(ke.getKeyCode() == KeyEvent.VK_ENTER)
if(ke.getKeyCode() == KeyEvent.VK_ENTER) {
frame.textFieldList.get(index).setText(null);
String str = ";";
frame.changeList(str, (JTextArea) frame.textAreaList.get(index),nbAxioms);
if(type == 0)
nbAxioms ++;
}
}
@Override

View File

@ -12,6 +12,7 @@ public class NewGenListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
frame.newTab();
}
}