Salve forumiani! Sono nuovo di questo forum e anche molto fresco riguardante la programmazione.
Sto cercando di creare un'applicazione che possa "loggare" un utente usando JFrame, JPane e JOptionPane, vi consiglio di copiare e incollare perché parlerò per righe.
Nella prima parte (rig. 1 - 40) creo tanti utenti per provare le funzioni successive.
Nella seconda parte (rig. 41 - 45) chiedo all'utente se è già registrato o meno.
Se l'utente è già registrato anche se metto email e password corrette non mi entra mai nell'if rig. 47.
Se l'utente è nuovo mi entra sempre nell'else rig. 58.
Non capisco dove sta l'inghippo!
codice:package applicazione;import java.awt.Color; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; public class Main { public static void main(String[] args) { JFrame app = new JFrame ("Applicazione di Alessandro"); JPanel background = new JPanel(); background.setBackground(Color.DARK_GRAY); app.add(background); app.setSize(500, 500); app.setVisible(true); Applicazione utenti = new Applicazione(); String email; String password; Utente u1 = new Utente ("vincenzo@gmail.com" , "asdfghjkl"); Utente u2 = new Utente ("alessandro@gmail.com" , "abcdefg"); Utente u3 = new Utente ("francesco@gmail.com" , "password"); Utente u4 = new Utente ("nicola@gmail.com" , "alicebob"); Utente u5 = new Utente ("mario@gmail.com" , "marioPass"); utenti.nuovoUtente(u1); utenti.nuovoUtente(u2); utenti.nuovoUtente(u3); utenti.nuovoUtente(u4); utenti.nuovoUtente(u5); u1.setNicknameUtente("Vinc99"); u2.setNicknameUtente("Ale38"); u3.setNicknameUtente("Frank"); u4.setNicknameUtente("Nico"); u5.setNicknameUtente("Rossi"); String nickname; boolean login = false; int scelta; Utente utente = new Utente(); while(!login) { scelta = JOptionPane.showConfirmDialog(background, "Sei registrato?"); email = JOptionPane.showInputDialog(background, "Inserisci email", "@gmail.com"); password = JOptionPane.showInputDialog(background, "Password: "); utente.setEmailUtente(email); utente.setPasswordUtente(password); if(scelta == JOptionPane.YES_OPTION) { //Sign in if(utenti.cercaUtente(utente) && utenti.password(utente)) { //Email corretta JOptionPane.showMessageDialog(background, "Utente trovato!", "Caricamento completato", JOptionPane.INFORMATION_MESSAGE); login = true; break; } JOptionPane.showMessageDialog(background, "Questo account non esiste!", "Caricamento errato", JOptionPane.ERROR_MESSAGE); } else if(scelta == JOptionPane.NO_OPTION) { //Sign up if(utenti.cercaUtente(utente)){ //Email già esistente JOptionPane.showMessageDialog(background, "Questa email è stata già registrata!", "Errore!", JOptionPane.ERROR_MESSAGE); } else { //Email nuova nickname = JOptionPane.showInputDialog(background, "Inserisci il nickname: "); utente.setNicknameUtente(nickname); login = true; break; } } } if(login) { JOptionPane.showMessageDialog(background, "Loggin success!", utente.getNicknameUtente() , JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(background, utente, "Scheda personale" , JOptionPane.INFORMATION_MESSAGE); } else JOptionPane.showMessageDialog(background, "Loggin failed!", "Errore!" , JOptionPane.ERROR_MESSAGE); app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }codice:@Override public int hashCode() { return emailUtente.hashCode(); }


Rispondi quotando

