Why does data not save into HashMap? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why does data not save into HashMap?

I am trying to create a log in system in Java using swing and hashmaps. But the data in the hash map does not save?? public class Login implements ActionListener { int enter = 0; static JTextField userName; JPanel mainPanel; static JLabel pass; static boolean correctUser = false; static boolean correctPass = false; static JButton ok; JPasswordField field; JButton newAccount; //Account Frame variables: JFrame accountFrame; JTextField user; JTextField password; JPanel accountPanel; String Password= ""; static String username = ""; boolean enteredPass = false; boolean enteredUserName = false; private static JFrame frame; private static JButton forgotPass; static JButton forgotUser; private HashMap<String, String> users = new HashMap<>(); Map<String, String> forgotUserName = new HashMap<>(); static int tryCount =0; static int count = 0; public Login() throws IOException { System.out.println(users.size()); ok = new JButton("OK"); frame = new JFrame("Login"); userName = new JTextField(20); userName.addActionListener(this); frame.setLocation(500,300); JLabel username = new JLabel("Username:"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); mainPanel = (JPanel) frame.getContentPane(); mainPanel.setBackground(Color.blue); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); mainPanel.add(username); mainPanel.add(userName); pass = new JLabel("Password:"); field = new JPasswordField(); field.addActionListener(this); mainPanel.add(pass); mainPanel.add(field); newAccount = new JButton("Create a new Account"); newAccount.addActionListener(this); mainPanel.add(newAccount); forgotPass = new JButton("Forgot Password"); forgotPass.addActionListener(this); mainPanel.add(forgotPass); forgotUser = new JButton("Forgot Username"); forgotUser.addActionListener(this); mainPanel.add(forgotUser); frame.pack(); } public void

18th Jun 2021, 10:57 PM
Jeremiah Hawthorne
2 Answers
0
you have mistaken in your java script first see properly and then run the if its working in running then there is symbol in corner of your there is option for save and clicked on saved it will saves your progeress
19th Jun 2021, 4:45 AM
UBAID ANSARI
UBAID ANSARI - avatar
0
Code is truncated. So it can't showing where you are using hashmap.. also here in SL , don't support graphics so no one can't test it here to find mistake.. So write only about hashmap code , and share Link to see is it working or not... hope it helps..
19th Jun 2021, 9:05 AM
Jayakrishna 🇮🇳