I am new to Java. I want to make a registration program which I will use later for Login. I want to get the user to input their User name (KorisnickoIme
), Password (Lozinka
) and Repeat password (PLozinka
); compare Lozink
a with PLozinka
; and if all is good, add Lozinka
as a value to a hashmap with key KorisnickoIme
.
The problem is that when I print lozinka
, I get nothing. So that means that I got nothing in the Hash map too, and I can't use it later for Login stuff.
public class RegistrujSeProzor {
static HashMap<String, Object> korisnici = new HashMap<>();
static String KorisnickoIme = "";
static String Lozinka = "";
static String PLozinka = "";
static void prozor () {
JFrame prozor = new JFrame();
prozor.setLayout(null);
prozor.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
prozor.setIconImage(new ImageIcon("res/purple.png").getImage());
prozor.setVisible(true);
prozor.setSize(400, 300);
prozor.setLocationRelativeTo(null);
prozor.setResizable(false);
Container contentPane = prozor.getContentPane();
JLabel label1 = new JLabel("Novo Korisnicko Ime : ");
JLabel label2 = new JLabel("Nova Lozinka : ");
JLabel label3 = new JLabel("Ponovte Lozinku : ");
label1.setBounds(10, 20, 200, 30);
label2.setBounds(10, 50, 200, 30);
label3.setBounds(10, 80, 200, 30);
contentPane.add(label1);
contentPane.add(label2);
contentPane.add(label3);
JTextField textField = new JTextField(20);
contentPane.add(textField);
textField.setBounds(140, 26, 200, 20);
KorisnickoIme = textField.getText();
JTextField textField2 = new JTextField(20);
contentPane.add(textField2);
textField2.setBounds(140, 57, 200, 20);
Lozinka = textField2.getText();
JTextField textField3 = new JTextField(20);
contentPane.add(textField3);
textField3.setBounds(140, 88, 200, 20);
PLozinka = textField3.getText();
JButton dPotvrdi = new JButton("Potvrdi");
dPotvrdi.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (Lozinka.equals(PLozinka)) {
korisnici.put(KorisnickoIme, Lozinka);
UlogujSeProzor.main(null);
prozor.dispose();
System.out.println(Lozinka);
}else{
JOptionPane.showMessageDialog(null,"Pogresno uneto Novo Korisnicko ime ili Lozinka ! "
+ "Pokusajte ponovo .");
RegistrujSeProzor.main(null);
}
}
});
JButton dNazad = new JButton("Nazad");
dNazad.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
LoginRegisterProzor.main(null);
prozor.dispose();
}
});
contentPane.add(dPotvrdi);
contentPane.add(dNazad);
dPotvrdi.setBounds(215, 215, 150, 30);
dNazad.setBounds(15, 215, 150, 30);
}
public static String getText() {
return KorisnickoIme;
}
public static void setText(String text) {
RegistrujSeProzor.KorisnickoIme = text;
}
public static String getText2() {
return Lozinka;
}
public static void setText2(String text2) {
RegistrujSeProzor.Lozinka = text2;
}
public static String getText3() {
return PLozinka;
}
public static void setText3(String text3) {
RegistrujSeProzor.PLozinka = text3;
}
public static void main(String[] args) {
prozor();
}