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() { public void closeTab() {
//TODO : Pour fermer un onglet, nécessite l'implémentation d'un button fermer grâce à la méthode newTab(). //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) { public void changeList(String stringToAdd, JTextArea list,int nbAxioms) {
if (stringToAdd == null) { if(nbAxioms>0)
switch(messageType) { JOptionPane.showMessageDialog(null, "Nombre maximal d'axiomes créés");
case 0: else {
list.setText("Axiome : \n");
case 1:
list.setText("Règles : \n");
default:
throw new IllegalArgumentException("Wrong argument given to method changeList");
}
}else{
list.append(stringToAdd); list.append(stringToAdd);
if (stringToAdd == ";")
nbAxioms++;
} }
} }
public String getAxiom(){ public String getAxiom(){
String str = ""; String str = "";
@ -106,19 +103,5 @@ public class MainFrame extends JFrame {
//TODO return the rules //TODO return the rules
return list; 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; MainFrame frame;
int index; 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.frame = frame;
this.index = index; this.index = index;
this.i = i; nbAxioms = 0;
this.type = type;
} }
@Override @Override
public void keyTyped(KeyEvent ke) { public void keyTyped(KeyEvent ke) {
if(ke.getKeyCode() != KeyEvent.VK_ENTER)
frame.changeList(String.valueOf(ke.getKeyChar()),i, (JTextArea) frame.textAreaList.get(index)); if(ke.getKeyCode() != KeyEvent.VK_ENTER && nbAxioms==0)
else{ frame.changeList(String.valueOf(ke.getKeyChar()), (JTextArea) frame.textAreaList.get(index),nbAxioms);
String str = ";\r\n";
frame.changeList(str,i, (JTextArea) frame.textAreaList.get(index));
frame.textFieldList.get(index).setText(null);
}
} }
@Override @Override
public void keyPressed(KeyEvent ke) { public void keyPressed(KeyEvent ke) {
if(ke.getKeyCode() == KeyEvent.VK_ENTER) if(ke.getKeyCode() == KeyEvent.VK_ENTER) {
frame.textFieldList.get(index).setText(null); frame.textFieldList.get(index).setText(null);
String str = ";";
frame.changeList(str, (JTextArea) frame.textAreaList.get(index),nbAxioms);
if(type == 0)
nbAxioms ++;
}
} }
@Override @Override

View File

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