From acac110c50827ca530edeae1984d4cd8894708a0 Mon Sep 17 00:00:00 2001 From: Arthur <78031901+Arthur7770@users.noreply.github.com> Date: Tue, 30 Mar 2021 17:37:14 +0200 Subject: [PATCH] Close button WORKS ! --- src/lsystem/screen/main/Listener.java | 10 ++++++---- src/lsystem/screen/main/MainFrame.java | 8 +++++++- src/lsystem/screen/main/Tab.java | 4 ++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/lsystem/screen/main/Listener.java b/src/lsystem/screen/main/Listener.java index 261583f..5c4e83a 100644 --- a/src/lsystem/screen/main/Listener.java +++ b/src/lsystem/screen/main/Listener.java @@ -31,11 +31,13 @@ public class Listener implements ActionListener, KeyListener, MouseWheelListener public void actionPerformed(ActionEvent e) { switch (type) { case "Close": - frame.getTab().removeTabAt(index-1); - frame.decreaseTab(); - for(int i = 0; i < frame.getTab().getComponentCount(); i++){ - frame.getTab().setTitleAt(i,"Génération"+(i+1)); + Component selected = frame.tabs.getSelectedComponent(); + if (selected != null) { + + frame.tabs.remove(selected); } + frame.decreaseTab(); + frame.renameTabs(); break; case "Help": diff --git a/src/lsystem/screen/main/MainFrame.java b/src/lsystem/screen/main/MainFrame.java index 8ab7240..70486ee 100644 --- a/src/lsystem/screen/main/MainFrame.java +++ b/src/lsystem/screen/main/MainFrame.java @@ -16,7 +16,7 @@ public class MainFrame extends JFrame { private int nbTabs; boolean helpWindow = false; private final JPanel basePanel; - private final JTabbedPane tabs; + public final JTabbedPane tabs; private final JButton newGen; private final JButton help; private final int nbRules; @@ -49,6 +49,7 @@ public class MainFrame extends JFrame { nbTabs++; new Tab(nbTabs, nbRules, tabs,this); + renameTabs(); } public JTabbedPane getTab(){ return tabs; @@ -98,5 +99,10 @@ public class MainFrame extends JFrame { } } + public void renameTabs(){ + for(int i =0;i