From 1c655b405f5b37604a99e932e4fe2f827934e4a8 Mon Sep 17 00:00:00 2001 From: Arthur <78031901+Arthur7770@users.noreply.github.com> Date: Fri, 12 Feb 2021 17:58:19 +0100 Subject: [PATCH] Made Listeners works --- src/lsystem/screen/MainFrame.java | 30 ++++++++++++++++--- src/lsystem/screen/listener/HelpListener.java | 10 ++++++- .../screen/listener/NewGenListener.java | 8 ++++- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/lsystem/screen/MainFrame.java b/src/lsystem/screen/MainFrame.java index dddfe82..ea77a5e 100644 --- a/src/lsystem/screen/MainFrame.java +++ b/src/lsystem/screen/MainFrame.java @@ -41,10 +41,10 @@ public class MainFrame extends JFrame { JToolBar toolBar = new JToolBar(); newGen = new JButton("Nouvelle génération"); - newGen.addActionListener(new NewGenListener()); + newGen.addActionListener(new NewGenListener(this)); toolBar.add(newGen); help = new JButton("Aide"); - help.addActionListener(new HelpListener()); + help.addActionListener(new HelpListener(this)); toolBar.add(help); this.setTitle("L-system interface"); @@ -106,8 +106,30 @@ public class MainFrame extends JFrame { list.append("-> "+stringToAdd + "\n"); } } - public void sendRule(){ - //TODO : send the string contain into a JTextField into the JTextAre ruleList or axiomList + public String getAxiom(){ + String str = ""; + // TODO : return the axiom + return str; + } + public ArrayList getRules(){ + ArrayList list= new ArrayList<>(); + //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); + } } diff --git a/src/lsystem/screen/listener/HelpListener.java b/src/lsystem/screen/listener/HelpListener.java index e5f1183..103409b 100644 --- a/src/lsystem/screen/listener/HelpListener.java +++ b/src/lsystem/screen/listener/HelpListener.java @@ -1,11 +1,19 @@ package lsystem.screen.listener; +import lsystem.screen.MainFrame; + import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class HelpListener implements ActionListener { + + MainFrame frame; + public HelpListener(MainFrame frame) { + this.frame = frame; + } + @Override public void actionPerformed(ActionEvent e) { - + frame.newHelp(); } } diff --git a/src/lsystem/screen/listener/NewGenListener.java b/src/lsystem/screen/listener/NewGenListener.java index 954b01e..21fbb56 100644 --- a/src/lsystem/screen/listener/NewGenListener.java +++ b/src/lsystem/screen/listener/NewGenListener.java @@ -2,10 +2,16 @@ package lsystem.screen.listener; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import lsystem.screen.MainFrame; public class NewGenListener implements ActionListener { + MainFrame frame; + public NewGenListener(MainFrame frame) { + this.frame = frame; + } + @Override public void actionPerformed(ActionEvent e) { - + frame.newTab(); } }