codice:
package org.schedule.Admin;
import *;
public class DatiDocenti_Admin {
private JTable t;
public Connection conn;
public JButton cancella;
public JButton modifica;
public JButton aggiorna;
public JTextField id;
public JTextField password;
public JTextField nominativo;
public JTextField username;
public JTextField img;
public JTextField dipartimento;
public JTextField email;
public JTextField tipo;
public JTextField fax;
public JTextField jTextField1;
public JTextField telefono;
public void leggitabella2(ActionEvent e) throws SQLException{
// costruzione nuova finestra
JDialog finestra2 = new JDialog();
@SuppressWarnings("unused")
//JTextArea lavagna2 = new JTextArea();
Font f2 = new Font(null, Font.BOLD,15);
ModTab miomodello = new ModTab("utente");
t = new JTable(miomodello);
t.setPreferredScrollableViewportSize(new Dimension(1000, 90));
t.getSelectionModel().addListSelectionListener(new RowListener());
/* Pulsante per cambiare i dati di un record. */
/*Pulsante per cancellare i dati di un record*/
finestra2.add("North", t);
finestra2.add(t);
{
JPanel PannelloBottoni = new JPanel();
finestra2.getContentPane().add(PannelloBottoni, BorderLayout.SOUTH);
{
nominativo = new JTextField();
PannelloBottoni.add(nominativo);
nominativo.setBounds(320, 85, 196, 22);
}
{
username = new JTextField();
PannelloBottoni.add(username);
username.setBounds(541, 84, 233, 22);
}
{
password = new JTextField();
PannelloBottoni.add(password);
password.setBounds(786, 82, 199, 22);
}
{
id = new JTextField();
PannelloBottoni.add(id);
id.setBounds(36, 85, 275, 22);
id.setEnabled(false);
}
{
cancella = new JButton();
PannelloBottoni.add(cancella);
cancella.setBounds(94, 238, 256, 85);
cancella.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/BottoneCancella.png")));
cancella.setBackground(new java.awt.Color(255,128,255));
cancella.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
cancella.setOpaque(false);
cancella.setBorderPainted(false);
cancella.setDebugGraphicsOptions(DebugGraphics.BUFFERED_OPTION);
cancella.setRolloverIcon(new ImageIcon(getClass().getResource("/img/BottoneCancella2.png")));
cancella.setPressedIcon(new ImageIcon(getClass().getResource("/img/BottoneCancella3.png")));
cancella.setMnemonic(KeyEvent.VK_UNDEFINED);
cancella.setFocusCycleRoot(true);
cancella.setSelected(true);
cancella.setFocusPainted(false);
cancella.setFocusTraversalPolicyProvider(true);
cancella.setContentAreaFilled(false);
cancella.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
try {
//System.out.println("ciao....");
cancellaRiga(e);
// Application.getInstance().getContext().getResourceMap(getClass()).injectComponents(getContentPane());
} catch (SQLException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
}
});
}
{
modifica = new JButton ("");
PannelloBottoni.add(modifica);
modifica.setBounds(510, 238, 256, 85);
modifica.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/BottoneModifica.png")));
modifica.setBackground(new java.awt.Color(255,128,255));
modifica.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
modifica.setOpaque(false);
modifica.setBorderPainted(false);
modifica.setDebugGraphicsOptions(DebugGraphics.BUFFERED_OPTION);
modifica.setRolloverIcon(new ImageIcon(getClass().getResource("/img/BottoneModifica2.png")));
modifica.setPressedIcon(new ImageIcon(getClass().getResource("/img/BottoneModifica3.png")));
modifica.setMnemonic(KeyEvent.VK_UNDEFINED);
modifica.setFocusCycleRoot(true);
modifica.setSelected(true);
modifica.setFocusPainted(false);
modifica.setFocusTraversalPolicyProvider(true);
modifica.setContentAreaFilled(false);
modifica.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
//System.out.println("ciao....");
modificaarchivio(e);
} catch (SQLException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
}
});
}
{
aggiorna = new JButton ();
PannelloBottoni.add(aggiorna);
aggiorna.setBounds(893, 238, 256, 85);
aggiorna.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/BottoneAggiorna.png")));
aggiorna.setBackground(new java.awt.Color(255,128,255));
aggiorna.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
aggiorna.setOpaque(false);
aggiorna.setBorderPainted(false);
aggiorna.setDebugGraphicsOptions(DebugGraphics.BUFFERED_OPTION);
aggiorna.setRolloverIcon(new ImageIcon(getClass().getResource("/img/BottoneAggiorna2.png")));
aggiorna.setPressedIcon(new ImageIcon(getClass().getResource("/img/BottoneAggiorna3.png")));
aggiorna.setMnemonic(KeyEvent.VK_UNDEFINED);
aggiorna.setFocusCycleRoot(true);
aggiorna.setSelected(true);
aggiorna.setFocusPainted(false);
aggiorna.setFocusTraversalPolicyProvider(true);
aggiorna.setContentAreaFilled(false);
aggiorna.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try {
leggitabella2(e);
} catch (SQLException ex) {
ex.printStackTrace();
}
}
});
}
{
JLabel labnominativo = new JLabel("");
PannelloBottoni.add(labnominativo);
labnominativo.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/Nominativo.png")));
labnominativo.setBounds(318, 60, 159, 26);
}
{
JLabel labusername = new JLabel ("");
PannelloBottoni.add(labusername);
labusername.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/username.png")));
labusername.setBounds(547, 59, 174, 26);
}
{
JLabel labpassword = new JLabel ("");
PannelloBottoni.add(labpassword);
labpassword.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/Password.png")));
labpassword.setBounds(781, 59, 198, 26);
}
{
JLabel labid = new JLabel ("") ;
PannelloBottoni.add(labid);
labid.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/Id utente.png")));
labid.setBounds(36, 59, 238, 29);
}
{
telefono = new JTextField();
PannelloBottoni.add(telefono);
telefono.setBounds(324, 178, 192, 22);
}
{
JLabel labtelefono = new JLabel("");
PannelloBottoni.add(labtelefono);
labtelefono.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/Telefono.png")));
labtelefono.setBounds(324, 151, 238, 29);
}
{
fax = new JTextField();
PannelloBottoni.add(fax);
fax.setBounds(547, 176, 224, 22);
}
{
tipo = new JTextField();
PannelloBottoni.add(tipo);
tipo.setBounds(1004, 82, 233, 22);
}
{
email = new JTextField();
PannelloBottoni.add(email);
email.setBounds(789, 176, 198, 22);
}
{
dipartimento = new JTextField();
PannelloBottoni.add(dipartimento);
dipartimento.setBounds(40, 178, 275, 22);
}
{
img = new JTextField();
PannelloBottoni.add(img);
img.setBounds(1005, 177, 203, 22);
}
{
JLabel labfax = new JLabel("");
PannelloBottoni.add(labfax);
labfax.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/Fax.png")));
labfax.setBounds(547, 149, 159, 29);
}
{
JLabel labtipo = new JLabel ("");
PannelloBottoni.add(labtipo);
labtipo.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/Tipo Utente.png")));
labtipo.setBounds(998, 57, 238, 29);
}
{
JLabel labemail = new JLabel ("");
PannelloBottoni.add(labemail);
labemail.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/E-mail.png")));
labemail.setBounds(789, 148, 167, 29);
}
{
JLabel labdipartimento = new JLabel("");
PannelloBottoni.add(labdipartimento);
labdipartimento.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/Dipartimento.png")));
labdipartimento.setBounds(39, 151, 275, 29);
}
{
JLabel labimmagine = new JLabel("") ;
PannelloBottoni.add(labimmagine);
labimmagine.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/Foto.png")));
labimmagine.setBounds(1005, 150, 238, 29);
}
PannelloBottoni.setLayout(null);
PannelloBottoni.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
PannelloBottoni.setBackground(new Color(0, 51, 255));
PannelloBottoni.setPreferredSize(new java.awt.Dimension(927, 367));
}
finestra2.setFont(f2);
finestra2.setTitle("Dati Docenti");
finestra2.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/img/logo_uni.png")));
finestra2.setSize(1280, 775);
//finestra2.setLocation(0,0);
finestra2.setVisible(true);
finestra2.setLayout(new BorderLayout());
finestra2.add(BorderLayout.NORTH,new JScrollPane(t));
finestra2.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
} // fine leggitabella
private class RowListener implements ListSelectionListener {
public void valueChanged(ListSelectionEvent event) {
if (event.getValueIsAdjusting()) {
return;
}
int row = t.getSelectedRow();
System.out.println("hai selezionato la riga:" + row);
id.setText ((String) t.getValueAt (row,0));
nominativo.setText ((String) t.getValueAt (row,1));
username.setText ((String) t.getValueAt (row,2));
password.setText ((String) t.getValueAt (row,3));
tipo.setText ((String) t.getValueAt (row,4));
dipartimento.setText ((String) t.getValueAt (row,5));
telefono.setText ((String) t.getValueAt (row,6));
fax.setText ((String) t.getValueAt (row,7));
email.setText ((String) t.getValueAt (row,8));
img.setText ((String) t.getValueAt (row,9));
}
}
public void cancellaRiga(ActionEvent e)throws SQLException, ClassNotFoundException{
SQLManager sqlm = new SQLManager ("com.mysql.jdbc.Driver","jdbc:mysql://localhost:3306/schedule","root","root");
String query = "delete from utente where id_utente = '"+ id.getText() +"'";
sqlm.esegui(query);
sqlm.close();
nominativo.setText("");
username.setText("");
password.setText("");
id.setText("");
telefono.setText("");
fax.setText("");
tipo.setText ("");
email.setText ("");
dipartimento.setText ("");
img.setText ("");
}
public void modificaarchivio(ActionEvent e)throws SQLException, ClassNotFoundException{
SQLManager sqlm = new SQLManager("com.mysql.jdbc.Driver","jdbc:mysql://localhost:3306/schedule","root","root");
String query = "update Utente set nominativo = '"+ nominativo.getText()+"', username= '"+ username.getText() +"', password ='"+ password.getText() +"', tipo_utente = '"+ tipo.getText() +"'," +
" dipartimento = '"+ dipartimento.getText() +"', telefono = '"+ telefono.getText() +"',fax = '"+ fax.getText() +"', email = '"+ email.getText() +"'," +
" img ='"+ img.getText() +"' where id_utente = '"+ id.getText() +"'";
sqlm.esegui(query);
sqlm.close();
nominativo.setText("");
username.setText("");
password.setText("");
id.setText("");
telefono.setText ("");
fax.setText ("");
tipo.setText ("");
email.setText ("");
dipartimento.setText ("");
img.setText ("");
}
}