class TableurTable extends JPanel {
public TableurTable () {
super(new GridLayout(1,0));
JTable table = new JTable(new MyTableModel());
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
JScrollPane scrollPane = new JScrollPane(table);
setUpResultColumn(table, table.getColumnModel().getColumn(3));
add(scrollPane);
}
public void setUpResultColumn(JTable table, TableColumn resultColumn)
{
//Set up the deitor for the result cells
JComboBox comboBox = new JComboBox();
comboBox.addItem("1 - 0");
comboBox.addItem("0.5 - 0.5");
comboBox.addItem("0 - 1");
comboBox.addItem("F - 1");
comboBox.addItem("1 - F");
comboBox.addItem("F - F");
comboBox.addItem("0 - 0");
resultColumn.setCellEditor(new DefaultCellEditor(comboBox));
//Set up tool tips for the sport cells
DefaultTableCellRenderer renderer =
new DefaultTableCellRenderer();
renderer.setToolTipText("Click for combo box");
resultColumn.setCellRenderer(renderer);
}
class MyTableModel extends AbstractTableModel {
String[] columnNames = { "Table", "Num pairing", "White", "result", "Num Pairing", "Black"};
Object[][] data = {{ new Integer(1), new Integer(1), "Dupont", "1 - 0", new Integer(3), "Durand"},
{new Integer(2), new Integer(4), "Martin", "1 - 0", new Integer(2), "Boulanger"}};
public int getColumnCount() {
return columnNames.length;
}
public int getRowCount() {
return data.length;
}
public String getColumnName(int col) {
return columnNames[col];
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
public boolean isCellEditable(int row, int col) {
/*if (3==col) return true;
else return false;*/
return true;
}
public void setValueAt(Object value, int row, int col) {
System.out.println("Setting value at " + row + "," +
col + " to " + value + "(an instance of " +
value.getClass() + ")");
data[row][col] = value;
fireTableCellUpdated(row, col);
}
}
}
//------------------------------------------------------------------------------------------
class PanneauPrincipal extends JPanel
/*implements Configuration*/ {
//Variables d'instance
private JMenuBar menuBar = new JMenuBar();
private JMenu menuFichier = new JMenu("Fichier");
private JMenu menuJoueur = new JMenu("Joueur");
private JMenu menuAppariement = new JMenu("Appariement");
private JFrame frame;
private ListOfPlayer listPlayer;
/** Item du menu fichier */
private JMenuItem itemNew = new JMenuItem("Nouveau");
private JMenuItem itemOpen = new JMenuItem("Ouvrir");
private JMenuItem itemSave = new JMenuItem("Sauver");
private JMenuItem itemQuit = new JMenuItem("Quitter");
/** Item du menu Joueur */
private JMenuItem itemAddPlayer = new JMenuItem("Ajouter joueur");
private JMenuItem itemOutPlayer = new JMenuItem("Sortir joueur");
/** Item du menu Appariement */
void executerActionOuvrir(){
JOptionPane.showMessageDialog(this,"Exécution de l'action Ouvrir");
}
void executerAddPlayer(){
DialogAddPlayer dialog=new DialogAddPlayer(frame );
// dialog.setLocationRelativeTo(frame);
if (dialog.returnOK())
listPlayer.addPlayer(dialog.getName(), dialog.getSurname(), dialog.getElo());
}
void executerActionQuitter(){
if (JOptionPane.showConfirmDialog(this, "Êtes-vous sûr de vouloir quitter",
"Confirmation",JOptionPane.YES_NO_CANCEL_OPTION)==JOptionPane.YES_OPTION)
System.exit(0);
}
//Constructeur
public PanneauPrincipal(JFrame frame, ListOfPlayer listPlayer) {
this.frame=frame;
this.listPlayer=listPlayer;
menuFichier.setText("Fichier");
menuFichier.add(itemNew);
itemOpen.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){executerActionOuvrir();}
});
menuFichier.add(itemOpen);
menuFichier.addSeparator();
menuFichier.add(itemSave);
menuFichier.addSeparator();
itemQuit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){executerActionQuitter();}
});
menuFichier.add(itemQuit);
itemAddPlayer.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){executerAddPlayer();}
});
menuJoueur.add(itemAddPlayer);
menuJoueur.add(itemOutPlayer);
setLayout(new BorderLayout());
add(menuBar, BorderLayout.NORTH);
menuBar.add(menuFichier);
menuBar.add(menuJoueur);
}
}
Partager