Devo creare un modulo di registrazione + accesso al db... la domanda primaria è: creo una classe utente e la sfrutto nella classe signup oppure è superflua al fine di registrare nel db?
Perché, ad esempio, per il form del login non son passato dalla classe utente ma ho direttamente interrogato il db...
Non so se mi son spiegato! :|
Io ho fatto così, per intenderci:
codice:
public class Utente {
private String nome;
private String cognome;
private String email;
private String categoria;
private String password;
public Utente(){
nome="";
cognome="";
email="";
categoria="";
password="";
}
public Utente(String nomeutente, String cognomeutente, String emailutente, String categoriautente, String passwordutente){
nome = nomeutente;
cognome = cognomeutente;
email = emailutente;
categoria = categoriautente;
password = passwordutente;
}
public void setNome(String nomeutente){
nome = nomeutente;
}
public void setCognome(String cognomeutente){
cognome = cognomeutente;
}
public void setEmail(String emailutente){
email = emailutente;
}
public void setCategoria(String categoriautente){
categoria = categoriautente;
}
public void setPassword(String passwordutente){
password = passwordutente;
}
public String getNome(){
return nome;
}
public String getCognome(){
return cognome;
}
public String getEmail(){
return email;
}
public String getCategoria(){
return categoria;
}
public String getPassword(){
return password;
}
}
codice:
import java.awt.Color;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class SignUp extends JFrame implements ActionListener {
private static final int LARGHEZZA = 360;
private static final int ALTEZZA = 250;
JTextField nameText, surnameText, emailText, categoriaText, pwdText;
public SignUp(){
super();
setTitle("Sign Up!");
setSize(LARGHEZZA,ALTEZZA);
JPanel pannello = new JPanel();
pannello.setLayout(null);
JLabel nameLabel = new JLabel("Nome: ");
nameLabel.setBounds(10,10,80,25);
pannello.add(nameLabel);
nameText = new JTextField(20);
nameText.setBounds(80,10,160,25);
pannello.add(nameText);
JLabel surnameLabel = new JLabel("Cognome: ");
surnameLabel.setBounds(10,50,80,25);
pannello.add(surnameLabel);
surnameText = new JTextField(20);
surnameText.setBounds(80,50,160,25);
pannello.add(surnameText);
JLabel emailLabel = new JLabel("Email: ");
emailLabel.setBounds(10,90,80,25);
pannello.add(emailLabel);
emailText = new JTextField(20);
emailText.setBounds(80,90,160,25);
pannello.add(emailText);
JLabel categoriaLabel = new JLabel("Impiego: ");
categoriaLabel.setBounds(10,130,80,25);
pannello.add(categoriaLabel);
categoriaText = new JTextField(20);
categoriaText.setBounds(80,130,160,25);
pannello.add(categoriaText);
JLabel pwdLabel = new JLabel("Password: ");
pwdLabel.setBounds(10,170,80,25);
pannello.add(pwdLabel);
pwdText = new JTextField(20);
pwdText.setBounds(80,170,160,25);
pannello.add(pwdText);
JButton signup = new JButton("Sign Up!");
signup.setBackground(Color.LIGHT_GRAY);
signup.addActionListener(this);
signup.setBounds(250,30, 80,25);
pannello.add(signup);
add(pannello);
}
public void ActionPerformed(ActionEvent e){
Utente utente = new Utente();
utente.setNome(nameText.getText());
utente.setPassword(pwdText.getText());
// registra(); metodo per registrare nel db
//da completare
}
public static void main(String[] args) {
// TODO Auto-generated method stub
SignUp signup = new SignUp();
signup.setVisible(true);
}
}