First close tab button implementation

This commit is contained in:
Arthur 2021-03-23 17:45:20 +01:00
parent 5bc68bc127
commit bbc74e1513
3 changed files with 26 additions and 11 deletions

View File

@ -33,6 +33,14 @@ public class Listener implements ActionListener, KeyListener {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
switch (type) { 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));
}
break;
case "Help": case "Help":
frame.newHelp(); frame.newHelp();
break; break;

View File

@ -47,8 +47,13 @@ public class MainFrame extends JFrame {
this.setPreferredSize(new Dimension(640,600)); this.setPreferredSize(new Dimension(640,600));
nbTabs++; nbTabs++;
new Tab(nbTabs, nbRules, tabs); new Tab(nbTabs, nbRules, tabs,this);
// test }
public JTabbedPane getTab(){
return tabs;
}
public void decreaseTab(){
nbTabs -=1;
} }
public void newHelp() { public void newHelp() {
@ -88,7 +93,7 @@ public class MainFrame extends JFrame {
JOptionPane.showMessageDialog(null, "Nombre maximal de générations atteintes"); JOptionPane.showMessageDialog(null, "Nombre maximal de générations atteintes");
else { else {
nbTabs++; nbTabs++;
new Tab(nbTabs, nbRules, tabs); new Tab(nbTabs, nbRules, tabs,this);
} }
} }

View File

@ -8,15 +8,12 @@ public class Tab extends JPanel{
int nbTabs; int nbTabs;
int nbRules; int nbRules;
JSpinner nbIterations; JSpinner nbIterations,itSpinner;
JTextField axiomeField; JTextField axiomeField,rulesField;
JTextField rulesField; JTextArea axiomList,rulesList;;
JTextArea axiomList; JButton submitButton, close;
JTextArea rulesList;
JSpinner itSpinner;
JButton submitButton;
public Tab(int nbTabs,int nbRules,JTabbedPane tabs) { public Tab(int nbTabs,int nbRules,JTabbedPane tabs,MainFrame frame) {
this.nbRules = nbRules; this.nbRules = nbRules;
this.nbTabs = nbTabs; this.nbTabs = nbTabs;
@ -72,6 +69,11 @@ public class Tab extends JPanel{
tab.add(southComponents); tab.add(southComponents);
tab.setLayout(new BoxLayout(tab,1)); tab.setLayout(new BoxLayout(tab,1));
close = new JButton("Close");
close.addActionListener(new Listener(frame,nbTabs,"Close",this));
tab.add(close);
tabs.addTab("Génération"+String.valueOf(nbTabs), tab); tabs.addTab("Génération"+String.valueOf(nbTabs), tab);
} }
public JTextArea textArea(String texte, int nb){ public JTextArea textArea(String texte, int nb){