Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Hashmap saves only the last entry i type. [JAVA]

hey there programers, 

I am making a very simple graphical booking system and im facing a problem with the hashmap.

So what im trying to do is that the user enters some information at textboxes and i save them in a hashmap.
The problem is that when i print that hashmap at the end of the program it only shows me the last entry of the user and not the previous ones.

Here is the code. [the code is a bit rough atm , maybe is a litle hard to read]

Code
public class GUI extends Application {
   static HashMap<String, String> RoomsMap = new HashMap(); //dimiourgia hashmap wste na peraso mesa oles tis kratiseis
    TextField textField1 = new TextField ();
    TextField textField2 = new TextField ();
    TextField textField3 = new TextField ();
    TextField textField4 = new TextField ();
    TextField textField5 = new TextField ();

void FillHashMapRooms() { //gemizei ta hashmap simfona me ta stoixeia p edose o xristis
       RoomsMap.put("Eidos-Domatiou ",textField1.getText());
       RoomsMap.put("Domatio-Name ",textField2.getText());
       RoomsMap.put("Domatio-Code ",textField3.getText());
       RoomsMap.put("Domatio-Price ",textField5.getText());
       RoomsMap.put("Domatio-Date ", textField4.getText());
   }

b18 = new Button();
       b18.setText("CONFIRM & ADD");
       b18.setOnAction(new EventHandler<ActionEvent>() {
       
           @Override public void handle(ActionEvent e) {
              FillHashMapRooms();
              window.setScene(s1);
       }});


these are the parts of the code that have to do with my problem.
b18 is the button that the user press when he has placed his information.

for any further info, let me know.
Thanks in advance fellas.
When you store the new user entered values in the HashMap, the older ones are overwritten.

The poor remain poor by acting rich.
(Jan 6, 2018 11:03 AM)XMR Wrote:  When you store the new user entered values in the HashMap, the older ones are overwritten.

yes i realize that.
Thats my problem,  do you know how i can make it work and save all the values?


well i just found the problem.
its a stupid one by me.
I provide the same key every time so the hashmap overwrites it.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by maryousJul 24, 2022 03:35 PM 0 161 Jul 24, 2022 03:35 PM
Last Post: maryous
[Java] by iHDCoolMay 4, 2021 07:51 AM 2 178 May 4, 2021 07:51 AM
Last Post: MavenGradle
[Java] by deadsh0tJan 10, 2019 07:30 AM 2 170 Jan 10, 2019 07:30 AM
Last Post: deadsh0t