From 0bc81d70a5d4dee1a03a674dee17545b49690714 Mon Sep 17 00:00:00 2001 From: Arthur <78031901+Arthur7770@users.noreply.github.com> Date: Wed, 17 Feb 2021 12:00:02 +0100 Subject: [PATCH] Interface works --- src/lsystem/Main.java | 26 -------------- src/lsystem/screen/MainFrame.java | 18 ++++++---- src/lsystem/screen/Tab.java | 2 ++ .../screen/listener/ClearListener.java | 4 ++- .../screen/listener/GenerateListener.java | 34 +++++++++++++++++++ 5 files changed, 51 insertions(+), 33 deletions(-) create mode 100644 src/lsystem/screen/listener/GenerateListener.java diff --git a/src/lsystem/Main.java b/src/lsystem/Main.java index 1618331..59b298d 100644 --- a/src/lsystem/Main.java +++ b/src/lsystem/Main.java @@ -15,33 +15,7 @@ public class Main { MainFrame frame = new MainFrame(); frame.setVisible(true); - /* SwingGLCanvas canvas = new SwingGLCanvas(); - - final Scanner scanner = new Scanner(System.in); - String axiom = null; - Parser parser = null; - final List rules = new ArrayList<>(); - int nbIterations = 0; - while(parser == null || !parser.isCorrect()) { - if(parser != null) - System.out.println("Vos règles ou votre axiome ne sont pas correctement écrites, veuillez recommencer"); - System.out.println("Axiome: "); - axiom = scanner.next(); - System.out.println("Règles: (\"finish\" quand vous avez fini): "); - while(rules.isEmpty() || !rules.get(rules.size() - 1).equals("finish")) { - rules.add(scanner.next()); - } - rules.remove(rules.size() - 1); - System.out.println("Nombre d'itérations: "); - nbIterations = scanner.nextInt(); - parser = new Parser(axiom, rules,nbIterations); - } - System.out.println("Réécriture, veuillez patientez..."); - Rewrite rewriter = new Rewrite(axiom, parser.parseRules(), nbIterations); - final String word = rewriter.rewrite(); - System.out.println(word); - scanner.close();*/ } diff --git a/src/lsystem/screen/MainFrame.java b/src/lsystem/screen/MainFrame.java index 8c7c725..72ee8bd 100644 --- a/src/lsystem/screen/MainFrame.java +++ b/src/lsystem/screen/MainFrame.java @@ -7,6 +7,7 @@ import lsystem.screen.listener.NewGenListener; import java.awt.*; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import javax.swing.*; @@ -93,14 +94,19 @@ public class MainFrame extends JFrame { } - public String getAxiom(){ - String str = ""; - // TODO : return the axiom + public String getAxiom(int index){ + String str = textAreaList.get(index).getText(); + str = str.substring(10,str.length()); return str; } - public ArrayList getRules(){ - ArrayList list= new ArrayList<>(); - //TODO return the rules + public List getRules(int index){ + List list = new ArrayList<>(); + String str = textAreaList.get(index).getText(); + str = str.substring(10,str.length()); + String[] strsplit = str.split("\n"); + for(int y = 0;y rules = frame.getRules(nbTabs+10); + Parser parser = new Parser(axiom,rules,12); + if(!parser.isCorrect()) { + JOptionPane.showMessageDialog(null, "Vos règles ou votre axiome ne sont pas correctement écrites, veuillez recommencer"); + new ClearListener(frame,nbTabs).forceAction(); + } + else{ + Rewrite rewriter = new Rewrite(axiom, parser.parseRules(), 12); + final String word = rewriter.rewrite(); + System.out.println(word); + } + } +}