From 9f0142dfb88921ed3ff2de2f25b1e28d3d3530c9 Mon Sep 17 00:00:00 2001 From: Arthur <78031901+Arthur7770@users.noreply.github.com> Date: Mon, 19 Apr 2021 11:09:17 +0200 Subject: [PATCH] Update Interface TextFields --- src/lsystem/screen/main/Listener.java | 25 ++++++++----------------- src/lsystem/screen/main/Tab.java | 17 ++--------------- 2 files changed, 10 insertions(+), 32 deletions(-) diff --git a/src/lsystem/screen/main/Listener.java b/src/lsystem/screen/main/Listener.java index 79a559e..4ce8374 100644 --- a/src/lsystem/screen/main/Listener.java +++ b/src/lsystem/screen/main/Listener.java @@ -107,32 +107,23 @@ public class Listener implements ActionListener, KeyListener, MouseWheelListener @Override public void keyTyped(KeyEvent ke) { - byte i = (byte) ((type.equals("Axiome")) ? 0 : 1); - if(nbAxioms==0 && ke.getKeyChar() != '\b') - tab.changeList(String.valueOf(ke.getKeyChar()), tab.getTextArea(i),nbAxioms); - if(ke.getKeyChar() == '\b'){ - String str = tab.getTextArea(i).getText(); - if(str.length()>10) { - if (!(str.endsWith(";\n") || str.endsWith(";"))){ - str = str.substring(10, str.length() - 1); - tab.getTextArea(i).setText(type + " : \n" + str); - } - } - } } @Override public void keyPressed(KeyEvent ke) { - byte i = (byte) ((type.equals("Axiome")) ? 0 : 1); - if(ke.getKeyCode() == KeyEvent.VK_ENTER) { + byte i = (byte) ((type.equals("Axiome")) ? 0 : 1); + String text = tab.getTextField(i).getText(); + text = ((text.charAt(text.length()-1)==';') ? "\n"+text : "\n"+text+";"); tab.getTextField(i).setText(null); - String str = ";"; - tab.changeList(str, tab.getTextArea(i),nbAxioms); - if(i == 0) + if(nbAxioms > 0 && i == 0) + JOptionPane.showMessageDialog(null, "Nombre maximal d'axiomes créés"); + else { + tab.getTextArea(i).append(text); nbAxioms ++; + } } } diff --git a/src/lsystem/screen/main/Tab.java b/src/lsystem/screen/main/Tab.java index b81e99a..af7196a 100644 --- a/src/lsystem/screen/main/Tab.java +++ b/src/lsystem/screen/main/Tab.java @@ -23,8 +23,8 @@ public class Tab extends JPanel{ this.nbRules = nbRules; this.nbTabs = nbTabs; - axiomList = textArea("Axiome : \n"); - rulesList = textArea("Règles : \n"); + axiomList = textArea("Axiome :"); + rulesList = textArea("Règles :"); JLabel itLabel = new JLabel("Nombre d'itérations : "); itSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 30, 1)); @@ -132,20 +132,7 @@ public class Tab extends JPanel{ return (i == 0) ? axiomeField : rulesField; } - /** - * Checks if the maximal axioms number has been reach, if not, add the given String into the axiomList or into the rulesList. - * @param stringToAdd the String to add into the JTextArea. - * @param list the JTextArea where to add the String (axiomList or rulesList). - * @param nb the number of Axioms that are already created (maximum 1). - */ - public void changeList(String stringToAdd, JTextArea list, int nb) { - if(nb > 0) - JOptionPane.showMessageDialog(null, "Nombre maximal d'axiomes créés"); - else { - list.append(stringToAdd); - } - } /** * @return A string which contains the axiom entered by the user.