però un'altra cosa...
ho gestito una cosa del genere sempre nello stesso progetto
con la Button Editor
avevo 10 partite(della giornata) messe in un HashMap e poi me le sono gestite tutte
codice:
/**
* @(#)ButtonEditor.java
*
*
* @author
* @version 1.00 2010/1/10
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Hashtable;
/**
* @version 1.0 11/09/98
*/
public class ButtonEditor extends DefaultCellEditor {
/**
*
*/
private static final long serialVersionUID = 1L;
protected JButton button;
protected JLabel lab;
private String label;
private boolean isPushed;
private int _row;
private Hashtable<Integer, Risultato> matchs;
private Risultato r;
private DesktopFrame superForm;
private MyInternalFrame frame;
public ButtonEditor(JCheckBox checkBox, MyInternalFrame frame, DesktopFrame sf) {
super(checkBox);
superForm=sf;
matchs=new Hashtable<Integer, Risultato>();
try{
this.frame=frame;
r=null;
}
catch(Exception e){
e.printStackTrace();
}
button = new JButton();
button.setOpaque(true);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fireEditingStopped();
}
}
);
}
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
System.out.println();
if (isSelected) {
button.setForeground(table.getSelectionForeground());
button.setBackground(table.getSelectionBackground());
}
else{
button.setForeground(table.getForeground());
button.setBackground(table.getBackground());
}
label = "...";
button.setText( label );
_row=row;
isPushed = true;
return button;
}
public Object getCellEditorValue() {
if (isPushed) {
for(int i=0; i<10; i++){
try{
int risA=frame.getRisultatoA(i);
int risB=frame.getRisultatoB(i);
this.matchs.put(i, new Risultato(frame.getIdMatch(i), risA, risB));
}
catch(Exception e){
e.printStackTrace();
}
}
Object riga=(Object)_row;
r = (Risultato)matchs.get(riga);
//JOptionPane.showMessageDialog(button ,"idpartita: "+r.getIdPartita());
modifyResult(r);
}
if(AlreadyPlayed(r.getIdPartita())){
label = "Giocata";
button.setText( label );
}
else{
label = "Calcola";
button.setText( label );
}
isPushed = false;
return new String( label ) ;
}
public boolean stopCellEditing() {
isPushed = false;
return super.stopCellEditing();
}
protected void fireEditingStopped() {
super.fireEditingStopped();
}
private boolean AlreadyPlayed(int idPartita){
boolean b;
LinkDB db=new LinkDB();
b=db.seePlayed(idPartita);
db.closeConnection();
return b;
}
public void modifyResult(Risultato filmpartita){
//qui chiamo le classi per la memorizzazione del risultato
//tu invece potresti aprirti il tuo file.....
}
}