Close button WORKS !

This commit is contained in:
Arthur 2021-03-30 17:37:14 +02:00
parent 9b969a42a7
commit acac110c50
3 changed files with 15 additions and 7 deletions

View File

@ -31,11 +31,13 @@ public class Listener implements ActionListener, KeyListener, MouseWheelListener
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
switch (type) { switch (type) {
case "Close": case "Close":
frame.getTab().removeTabAt(index-1); Component selected = frame.tabs.getSelectedComponent();
frame.decreaseTab(); if (selected != null) {
for(int i = 0; i < frame.getTab().getComponentCount(); i++){
frame.getTab().setTitleAt(i,"Génération"+(i+1)); frame.tabs.remove(selected);
} }
frame.decreaseTab();
frame.renameTabs();
break; break;
case "Help": case "Help":

View File

@ -16,7 +16,7 @@ public class MainFrame extends JFrame {
private int nbTabs; private int nbTabs;
boolean helpWindow = false; boolean helpWindow = false;
private final JPanel basePanel; private final JPanel basePanel;
private final JTabbedPane tabs; public final JTabbedPane tabs;
private final JButton newGen; private final JButton newGen;
private final JButton help; private final JButton help;
private final int nbRules; private final int nbRules;
@ -49,6 +49,7 @@ public class MainFrame extends JFrame {
nbTabs++; nbTabs++;
new Tab(nbTabs, nbRules, tabs,this); new Tab(nbTabs, nbRules, tabs,this);
renameTabs();
} }
public JTabbedPane getTab(){ public JTabbedPane getTab(){
return tabs; return tabs;
@ -98,5 +99,10 @@ public class MainFrame extends JFrame {
} }
} }
public void renameTabs(){
for(int i =0;i<nbTabs;i++){
tabs.setTitleAt(i,("Génération"+(i+1)));
}
}
} }

View File

@ -6,7 +6,7 @@ import java.util.Arrays;
public class Tab extends JPanel{ public class Tab extends JPanel{
int nbTabs; public int nbTabs;
int nbRules; int nbRules;
public JSpinner itSpinner; public JSpinner itSpinner;
JTextField axiomeField,rulesField; JTextField axiomeField,rulesField;
@ -71,7 +71,7 @@ public class Tab extends JPanel{
tab.setLayout(new BoxLayout(tab,1)); tab.setLayout(new BoxLayout(tab,1));
close = new JButton("Close"); close = new JButton("Close");
close.addActionListener(new Listener(frame,nbTabs,"Close",this)); close.addActionListener(new Listener(frame,this.nbTabs,"Close",this));
tab.add(close); tab.add(close);