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) {
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":

View File

@ -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<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{
int nbTabs;
public int nbTabs;
int nbRules;
public JSpinner itSpinner;
JTextField axiomeField,rulesField;
@ -71,7 +71,7 @@ public class Tab extends JPanel{
tab.setLayout(new BoxLayout(tab,1));
close = new JButton("Close");
close.addActionListener(new Listener(frame,nbTabs,"Close",this));
close.addActionListener(new Listener(frame,this.nbTabs,"Close",this));
tab.add(close);