codice:
class valoriTabella extends JPanel implements ActionListener
{
public Connection con;
public Statement st;
public int results;
public String upd, piro, v1matr;
public JTable tabella;
private JCambioNCoils pjp;
public JButton salva;
public JLabel commento, testata;
public String[][] Squal;
public valoriTabella(JCambioNCoils pjp)
{
this.pjp = pjp;
int i,i1;
v1matr = pjp.vmatr;
commento = new JLabel("Cambia il N. di Coils e salva");
testata = new JLabel("Matricola Diametro Spessore Qualità");
salva = new JButton(" Salva ");
salva.setBounds(200,140,80,20);
commento.setBounds(10,150,350,20);
testata.setBounds(10,20,350,20);
add(commento);
add(testata);
add(salva);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:Coils");
st = con.createStatement();
upd = "SELECT * FROM Coils1 WHERE fmatr = '"+ v1matr +"';";
ResultSet results = st.executeQuery(upd);
i=0;
String[] colHeads = {"Matricola","Diametro","Spessore","Qualità"};
Squal = new String[5][4];
Squal[0][0]="";
Squal[1][0]="";
Squal[2][0]="";
Squal[3][0]="";
Squal[4][0]="";
Squal[0][1]="";
Squal[1][1]="";
Squal[2][1]="";
Squal[3][1]="";
Squal[4][1]="";
Squal[0][2]="";
Squal[1][2]="";
Squal[2][2]="";
Squal[3][2]="";
Squal[4][2]="";
Squal[0][3]="";
Squal[1][3]="";
Squal[2][3]="";
Squal[3][3]="";
Squal[4][3]="";
while (results.next())
{
Squal[i][0] =results.getString("fmatr");
Squal[i][1] =results.getString("fdiam");
Squal[i][2] =results.getString("fspess");
Squal[i][3] =results.getString("fqua");
i++;
}
i=1;
Object[][] data =
{
{Squal[0][0],Squal[0][1],Squal[0][2],Squal[0][3]},
{Squal[1][0],Squal[1][1],Squal[1][2],Squal[1][3]},
{Squal[2][0],Squal[2][1],Squal[2][2],Squal[2][3]},
{Squal[3][0],Squal[3][1],Squal[3][2],Squal[3][3]},
{Squal[4][0],Squal[4][1],Squal[4][2],Squal[4][3]}
};
JTable tabella = new JTable(data,colHeads);
tabella.setBounds(10,40,350,80);
add(tabella);
}
catch(Exception e)
{
}
salva.addActionListener(this);
}
public void actionPerformed(ActionEvent evento)
{
Object s3 = evento.getSource();
if (s3==salva)
{
salvaTabella();
}
}
public void salvaTabella()
{
try
{
String[][] cella = new String[5][3];
cella[0][0] = tabella.getValueAt(0,0).toString();
commento.setText("C:"+cella[0][0]);
}
catch(Exception e)
{
commento.setText("C:"+e);
}
}
}
class valoriTabella1 extends JFrame
{
public valoriTabella1(int xLoc,int yLoc, JCambioNCoils jcn)
{
setSize(400,200);
setTitle("Certificati S.I.M. s.r.l. by Antonio Pompilii");
setResizable(false);
setLocation(xLoc,yLoc);
valoriTabella valoriTabella2 = new valoriTabella( jcn );
Container contentPane = getContentPane();
valoriTabella2.setLayout(null);
contentPane.add(valoriTabella2);
}
}