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 70 71 72 73 74 75 76 77 78 79 80 81
|
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
public class PlanetTable {
public static void main(String[] args) {
JFrame frame = new PlanetTableFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class PlanetTableFrame extends JFrame {
public PlanetTableFrame() {
setTitle("PlanetTable");
setSize(600, 300);
jeuEssai();
TableModel model = new Investissement(person);
JTable table = new JTable(model);
add(new JScrollPane(table), BorderLayout.CENTER);
ajouter = new JButton("Ajouter");
ajouter.addActionListener(new
ActionListener()
{
public void actionPerformed(ActionEvent event) {
String name = JOptionPane.showInputDialog(null,"Entrez un nom");
person.add(name);
}
}
);
JPanel p = new JPanel();
p.add(ajouter);
add(p, BorderLayout.NORTH);
}
public void jeuEssai() {
person.add("Damien");
person.add("Guillaume");
person.add("Pierre");
}
private JButton ajouter;
private ArrayList<String> person = new ArrayList<String>();
}
class Investissement extends AbstractTableModel {
public Investissement(ArrayList<String> tableau) {
tableauDonnee = tableau;
}
public int getRowCount() {
return tableauDonnee.size();
}
public int getColumnCount() {
return 1;
}
public void modifiertableau(ArrayList<String> tableau) {
tableauDonnee = tableau;
}
public Object getValueAt(int r, int c) {
return tableauDonnee.get(r);
}
public String getColumnName(int c) {
return "Nom";
}
private ArrayList<String> tableauDonnee = new ArrayList<String>();
} |
Partager