Bonjour ,

j'essaie d'ajouter dans une jtable, suivant un tutoriel vu sur le net.
Mais le code si dessous n'ajoite rien a la Jtable , lorsque je clic sur le bouton "Ajouter"

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JButton;
import javax.swing.JPanel;
 
public class FenetreJtable extends JFrame {
	private  JPanel PanBoutons=new JPanel();
	private JButton BtnAjout=new JButton("Ajouter");
	private JButton BtnSupp=new JButton("Supprimer");
	public FenetreJtable(){
		super();
		setTitle("Fenetre de Jtable");
		setSize(560,285);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setLocationRelativeTo(null);
		PanBoutons.add(BtnAjout);
		PanBoutons.add(BtnSupp);
		JTable laTable=new JTable(new ModelDynamikObjets());
		BtnAjout.addActionListener(new AjoutListener());
		getContentPane().add(new JScrollPane(laTable),BorderLayout.CENTER);
	    getContentPane().add(PanBoutons,BorderLayout.SOUTH);
	}
	class AjoutListener implements ActionListener{		
		@Override
		public void actionPerformed(ActionEvent event) {
			new ModelDynamikObjets().addAmi(new Ami("blaise", "mpula", Color.GREEN, false, Sport.FOOTBALL));
			System.out.println("yes");
		}
	}
 
	public static void main(String[] args) {
		new FenetreJtable().setVisible(true);
	}}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.awt.Color;
import java.util.ArrayList;
 
 
import javax.swing.table.AbstractTableModel;
 
 
public class ModelDynamikObjets extends AbstractTableModel{
	/**
         * 
         */
	private static final long serialVersionUID = 1L;
	private final ArrayList<Ami> amis=new ArrayList<Ami>();
	private final String []entetes={"nom","prenom","couleur","homme","Sport"};
 
	public ModelDynamikObjets(){
		super();
		amis.add(new Ami("ouf","confiseri",Color.RED,true,Sport.TENNIS));
		amis.add(new Ami("bande","essai",Color.blue,false,Sport.NATATION));
		amis.add(new Ami("only","java",Color.RED,true,Sport.TENNIS));
		amis.add(new Ami("jtable","dynamik",Color.BLACK,true,Sport.FOOTBALL));
		amis.add(new Ami("modele","test",Color.YELLOW,true,Sport.RIEN));
		amis.add(new Ami("for","an",Color.BLACK,true,Sport.NATATION));
		amis.add(new Ami("example","thanks",Color.RED,true,Sport.TENNIS));
	}
	@Override
	public int getColumnCount() {
		// TODO Auto-generated method stub
		return entetes.length;
	}
 
	@Override
	public int getRowCount() {
		// TODO Auto-generated method stub
		return amis.size();
	}
 
	@Override
	public Object getValueAt(int rowindex, int ColumnIndex) {
		// TODO Auto-generated method stub
		switch (ColumnIndex) {
		case 0:
			return amis.get(rowindex).getNom();
		case 1:
			return amis.get(rowindex).getPrenom();
		case 2:
			return amis.get(rowindex).getCouleur();
		case 3:
			return amis.get(rowindex).isHomme();
		case 4:
			return amis.get(rowindex).getSport();
		default:
			return null;
		}	}
 
	public String getColumnName(int ColumnIndex) {
		return entetes[ColumnIndex];		
	}
 
	public void addAmi(Ami ami){
		amis.add(ami);
		fireTableRowsInserted(amis.size()-1, amis.size()-1);
	}
	public void removeAmi(int RowIndex){
		amis.remove(RowIndex);
		fireTableRowsDeleted(RowIndex, RowIndex);
	}}
 
Merci de m'indiquer ce qui manque a ce code