codice:
package Schedule.Interfacce;
import *;
@SuppressWarnings("serial")
public class PannelloLogin {
public JPasswordField jPasswordField1;
public JLabel jLabelPassword;
public JButton jButton1;
public JLabel jLabelUsername;
public JTextField textFieldUsername;
public JPanel jPanel1;
public JLabel LabLogin;
public static boolean utenteLoggato = false;
@SuppressWarnings("unused")
public JPanel getJContentPane()
{
if(jPanel1 == null) {
jPanel1 = new JPanel();
FormLayout jPanel1Layout = new FormLayout(
"max(p;5dlu), max(p;5dlu), 138dlu, 95dlu, max(p;5dlu)",
"max(p;5dlu), max(p;5dlu), 8dlu, 17dlu, 37dlu, max(p;5dlu), 62dlu, max(p;5dlu), 62dlu");
jPanel1.setLayout(jPanel1Layout);
jPanel1.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
jPanel1.setBackground(new Color(0, 51, 255));
jPanel1.setPreferredSize(new java.awt.Dimension(542, 367));
jPanel1.add(getTextFieldUsername(), new CellConstraints("4, 4, 1, 1, default, default"));
jPanel1.add(getJPasswordField1(), new CellConstraints("4, 5, 1, 1, default, default"));
jPanel1.add(getJLabelUsername(), new CellConstraints("3, 4, 1, 1, default, default"));
jPanel1.add(getJButton1(), new CellConstraints("4, 7, 2, 1, default, default"));
jPanel1.add(getJLabelPassword(), new CellConstraints("3, 5, 1, 1, default, default"));
jPanel1.add(getLabLogin(), new CellConstraints("2, 1, 3, 1, default, default"));
}
return jPanel1;
}
public JTextField getTextFieldUsername() {
if(textFieldUsername == null) {
textFieldUsername = new JTextField();
}
return textFieldUsername;
}
public JPasswordField getJPasswordField1() {
if(jPasswordField1 == null) {
jPasswordField1 = new JPasswordField();
}
return jPasswordField1;
}
private JLabel getJLabelUsername() {
if(jLabelUsername == null) {
jLabelUsername = new JLabel();
jLabelUsername.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/username.png")));
}
return jLabelUsername;
}
public JButton getJButton1() {
if(jButton1 == null) {
jButton1 = new JButton();
jButton1.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/entra.png")));
jButton1.setBackground(new java.awt.Color(255,128,255));
jButton1.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
jButton1.setOpaque(false);
jButton1.setBorderPainted(false);
jButton1.setDebugGraphicsOptions(DebugGraphics.BUFFERED_OPTION);
jButton1.setRolloverIcon(new ImageIcon(getClass().getResource("/img/entra2.png")));
jButton1.setPressedIcon(new ImageIcon(getClass().getResource("/img/entraClick.png")));
jButton1.setMnemonic(KeyEvent.VK_UNDEFINED);
jButton1.setFocusCycleRoot(true);
jButton1.setSelected(true);
jButton1.setFocusPainted(false);
jButton1.setFocusTraversalPolicyProvider(true);
jButton1.setContentAreaFilled(false);
jButton1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
jButton1.addActionListener(new ActionListener() {
@SuppressWarnings("deprecation")
public void actionPerformed(ActionEvent evt) {
boolean controllo = true;
String[] dati = {textFieldUsername.getText(), jPasswordField1.getText()};
ControlManager cm = new ControlManager();
controllo = cm.controllaDatiVuoti(dati);
if(controllo){
//tutti i controlli sono andati a buon fine;
try {
controllaCredenziali();
}catch(Exception ex){
ex.printStackTrace();
}
}}}
);
}
return jButton1;
}
private JLabel getJLabelPassword() {
if(jLabelPassword == null) {
jLabelPassword = new JLabel();
jLabelPassword.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/password.png")));
}
return jLabelPassword;
}
private JLabel getLabLogin() {
if(LabLogin == null) {
LabLogin = new JLabel();
LabLogin.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/login.png")));
}
return LabLogin;
}
@SuppressWarnings("deprecation")
public void controllaCredenziali()
{
SQLManager sqlm = new SQLManager("com.mysql.jdbc.Driver","jdbc:mysql://localhost:3306/schedule","root","root");
String query = "select * from Utente where username = ? and password = ?";
String[] parametri = new String[] {textFieldUsername.getText(), jPasswordField1.getText()};
boolean esitoLogin = sqlm.verificaEsistenzaRecord(query,parametri);
if(esitoLogin){
//utente loggato
utenteLoggato = false;
//JOptionPane.showMessageDialog(null, "Utente loggato" ,"Login", JOptionPane.INFORMATION_MESSAGE);
if ( !jPasswordField1.getText().equals("00000") ) {
// Testa se la stringa è diversa da "qualcosa"
//jPanel1.setVisible(false);
DatiDocente docente = new DatiDocente(textFieldUsername.getText());
docente.getJFrame().setVisible(true);
jPasswordField1.setText("");
textFieldUsername.setText("");
}
else{
Admin admin = new Admin(textFieldUsername.getText());
admin.getJFrame().setVisible(true);
jPasswordField1.setText("");
textFieldUsername.setText("");
}
}else{
//utente NON loggato
ControlManager c= new ControlManager();
c.MessaggioErroreLogin();
}
sqlm.close(); //questa chiamata è importantissima onde evitare di lasciare troppe connessioni aperte verso il DB
}
}
codice:
package Schedule.Interfacce;
import *;
public class Admin {
private JFrame jFrame = null;
private JPanel jContentPane = null;
private JMenuBar jJMenuBar = null;
private JMenu fileMenu = null;
private JMenu helpMenu = null;
private JMenuItem exitMenuItem = null;
private JMenuItem aboutMenuItem = null;
private JDialog aboutDialog = null;
private JPanel aboutContentPane = null;
private JLabel aboutVersionLabel = null;
private JMenu AggiungiDataBaseMenu = null;
private JMenuItem AggiungiDataBaseMenuItem = null;
private String UsernameDocente;
public String getUsernameDocente() {
return UsernameDocente;
}
public void setUsernameDocente(String UsernameDocente) {
this.UsernameDocente = UsernameDocente;
}
public JFrame getJFrame() {
if (jFrame == null) {
jFrame = new JFrame();
//jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.setJMenuBar(getJJMenuBar());
jFrame.setSize(1504, 902);
jFrame.setContentPane(getJContentPane());
jFrame.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/img/logo_uni.png")));
jFrame.setTitle("Benvenuto/a " + this.getUsernameDocente() );
jFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
return jFrame;
}
public JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.setBackground(new Color(0, 153, 204));
FormLayout jContentPaneLayout = new FormLayout(
"800dlu",
"max(p;5dlu)");
jContentPane.setLayout(jContentPaneLayout);
//@SuppressWarnings("unused")
PannelloAdminStart PA=new PannelloAdminStart();
JPanel admin = PA.getJContentPane();
jContentPane.add(admin, new CellConstraints("1, 1, 1, 1, default, default"));
admin.setVisible(true);
}
return jContentPane;
}
private JMenuBar getJJMenuBar() {
if (jJMenuBar == null) {
jJMenuBar = new JMenuBar();
jJMenuBar.setBackground(Color.blue);
jJMenuBar.add(getFileMenu());
jJMenuBar.add(getJMenu());
jJMenuBar.add(getHelpMenu());
}
return jJMenuBar;
}
private JMenu getJMenu() {
if (AggiungiDataBaseMenu == null) {
AggiungiDataBaseMenu = new JMenu();
AggiungiDataBaseMenu.setText("Aggiungi Data Base");
AggiungiDataBaseMenu.setIcon(new ImageIcon(getClass().getResource("/img/registra.png")));
AggiungiDataBaseMenu.add(getRegistraMenuItem());
AggiungiDataBaseMenu.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
return AggiungiDataBaseMenu;
}
private JMenuItem getRegistraMenuItem() {
if (AggiungiDataBaseMenuItem == null) {
AggiungiDataBaseMenuItem= new JMenuItem();
AggiungiDataBaseMenuItem.setText("Aggiungi Data Base");
AggiungiDataBaseMenuItem.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
AggiungiDataBaseMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
TableDataBase db = new TableDataBase();
db.setVisible(true);
}
});
}
return AggiungiDataBaseMenuItem;
}
private JMenu getFileMenu() {
if (fileMenu == null) {
fileMenu = new JMenu();
fileMenu.setText("Uscita");
fileMenu.add(getExitMenuItem());
fileMenu.setIcon(new ImageIcon(getClass().getResource("/img/Bclose.png")));
fileMenu.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
return fileMenu;
}
private JMenu getHelpMenu() {
if (helpMenu == null) {
helpMenu = new JMenu();
helpMenu.setText("Help in linea");
helpMenu.add(getAboutMenuItem());
helpMenu.setIcon(new ImageIcon(getClass().getResource("/img/Help.png")));
helpMenu.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
return helpMenu;
}
private JMenuItem getExitMenuItem() {
if (exitMenuItem == null) {
exitMenuItem = new JMenuItem();
exitMenuItem.setText("Esci");
exitMenuItem.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
exitMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ControlManager cm = new ControlManager();
cm.MessaggioLogout();
System.exit(0);
}
});
}
return exitMenuItem;
}
private JMenuItem getAboutMenuItem() {
if (aboutMenuItem == null) {
aboutMenuItem = new JMenuItem();
aboutMenuItem.setText("Help in linea");
aboutMenuItem.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
aboutMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JDialog aboutDialog = getAboutDialog();
aboutDialog.pack();
Point loc = getJFrame().getLocation();
loc.translate(20, 20);
aboutDialog.setLocation(loc);
aboutDialog.setVisible(true);
}
});
}
return aboutMenuItem;
}
/**
* This method initializes aboutDialog
*
* @return javax.swing.JDialog
*/
private JDialog getAboutDialog() {
if (aboutDialog == null) {
aboutDialog = new JDialog(getJFrame(), true);
aboutDialog.setTitle("Help in linea");
aboutDialog.setContentPane(getAboutContentPane());
aboutDialog.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
return aboutDialog;
}
/**
* This method initializes aboutContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getAboutContentPane() {
if (aboutContentPane == null) {
aboutContentPane = new JPanel();
aboutContentPane.setLayout(new BorderLayout());
aboutContentPane.add(getAboutVersionLabel(), BorderLayout.CENTER);
}
return aboutContentPane;
}
/**
* This method initializes aboutVersionLabel
*
* @return javax.swing.JLabel
*/
private JLabel getAboutVersionLabel() {
if (aboutVersionLabel == null) {
aboutVersionLabel = new JLabel();
aboutVersionLabel.setText(" Pannello Aiuto");
aboutVersionLabel.setHorizontalAlignment(SwingConstants.CENTER);
}
return aboutVersionLabel;
}
/**
* Launches this application
*/
public Admin(String UsernameDocente) {
super();
this.UsernameDocente = UsernameDocente;
}
}