Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
MyBancoCredito - Framereg.java

Framereg.java

Caricato da: Bonny
Scarica il programma completo

  1. package jcredito;
  2. import java.awt.*;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5. import javax.swing.*;
  6.  
  7. public class Framereg extends JFrame implements ActionListener {
  8.  
  9.     private JButton invia = new JButton("Sent");
  10.     private JButton reset = new JButton("Reset");
  11.     private JTextField nome = new JTextField(15);
  12.     private JPasswordField psw = new JPasswordField(15);
  13.     private JTextField credito = new JTextField(15);
  14.     private JPanel p = new JPanel();
  15.     private JPanel pb = new JPanel();
  16.     private Utente ut;
  17.     private Jdbmanager jdb;
  18.     boolean flag;
  19.     private Framemodulo fx;
  20.  
  21.     public Framereg(boolean flag) {
  22.  
  23.         super("Modulo registrazione");
  24.         this.flag = flag;
  25.         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  26.         p.setLayout(new GridLayout(3, 3, 10, 10));
  27.         p.setBackground(new Color(0, 60, 95));
  28.         JLabel l1 = new JLabel(" User name:");
  29.         l1.setFont(new Font("Arial", Font.BOLD, 14));
  30.         l1.setForeground(Color.ORANGE);
  31.         p.add(l1);
  32.         p.add(nome);
  33.         JLabel l2 = new JLabel(" Password:");
  34.         l2.setFont(new Font("Arial", Font.BOLD, 14));
  35.         l2.setForeground(Color.ORANGE);
  36.         p.add(l2);
  37.         p.add(psw);
  38.         JLabel l3 = new JLabel(" Credito:");
  39.         l3.setFont(new Font("Arial", Font.BOLD, 14));
  40.         l3.setForeground(Color.ORANGE);
  41.         p.add(l3);
  42.         p.add(credito);
  43.         pb.setBackground(new Color(0, 60, 95));
  44.         pb.add(reset);
  45.         pb.add(invia);
  46.         reset.addActionListener(this);
  47.         invia.addActionListener(this);
  48.         this.getContentPane().add(p, "Center");
  49.         this.getContentPane().add(pb, "South");
  50.         this.setVisible(true);
  51.         this.setBounds(340, 200, 400, 200);
  52.          this.setResizable(false);
  53.         this.pack();
  54.         resetTxt();
  55.         l3.setVisible(this.flag);
  56.         credito.setVisible(this.flag);
  57.     }
  58.  
  59.     private void resetTxt() {
  60.         nome.setText(null);
  61.         psw.setText(null);
  62.         credito.setText(null);
  63.         nome.requestFocus();
  64.     }
  65.  
  66.     public void actionPerformed(ActionEvent e) {
  67.  
  68.         if ("Reset".equals(e.getActionCommand())) {
  69.             resetTxt();
  70.         } else if ("Sent".equals(e.getActionCommand())) {
  71.  
  72.             if (this.flag) {
  73.                 if (!nome.getText().equals("") && !psw.getText().equals("") && !credito.getText().equals("")) {
  74.                     ut = new Utente(nome.getText(), psw.getText(), Long.valueOf(credito.getText()));
  75.                     jdb = new Jdbmanager();
  76.                     if (jdb.reg(ut)) {
  77.                         JOptionPane.showMessageDialog(null, "Accaunt registrato con successo!", "msg", JOptionPane.INFORMATION_MESSAGE);
  78.                         fx = new Framemodulo(nome.getText());
  79.                         resetTxt();
  80.                         setVisible(false);
  81.                     } else {
  82.                         JOptionPane.showMessageDialog(null, "Devi cambiare user name '" + nome.getText() + "' \ngia presente nell'archivio.", "Attenzione", JOptionPane.WARNING_MESSAGE);
  83.                         resetTxt();
  84.                     }
  85.                 } else {
  86.                     JOptionPane.showMessageDialog(null, "Devi riempire tutti i campi", "msg", JOptionPane.INFORMATION_MESSAGE);
  87.                     resetTxt();
  88.                 }
  89.             } else {
  90.                 if (!nome.getText().equals("") && !psw.getText().equals("")) {
  91.                     ut = new Utente(nome.getText(), psw.getText());
  92.                     jdb = new Jdbmanager();
  93.                     if (jdb.login(ut)) {
  94.                          fx = new Framemodulo(nome.getText());
  95.                         resetTxt();
  96.                         setVisible(false);
  97.                     } else {
  98.                         JOptionPane.showMessageDialog(null, "Login fallito!!", "Attenzione", JOptionPane.WARNING_MESSAGE);
  99.                         resetTxt();
  100.                     }
  101.                 } else {
  102.                     JOptionPane.showMessageDialog(null, "Devi riempire tutti i campi", "msg", JOptionPane.INFORMATION_MESSAGE);
  103.                     resetTxt();
  104.                 }
  105.             }
  106.         }
  107.     }
  108. }