I am coding for a Who Wants To Be A Millionaire game and I have the questions for the game stored in a text file. I have the questions file read into a Hashmap but now I would like to portray the contents of the HashMap for e.g. the question and the multiple choice answers one by one on a JLabel for the question and 4 different buttons for the multiple choice answers on my GUI for the game. Any ideas on how I could do that?
Asked
Active
Viewed 17 times
-2
-
1For [example](https://stackoverflow.com/questions/70400047/buttons-within-buttons-in-java-gui/70400922#70400922); [example](https://stackoverflow.com/questions/31602113/listener-placement-adhering-to-the-traditional-non-mediator-mvc-pattern/31604919#31604919); [example](https://stackoverflow.com/questions/30925564/why-is-my-jlabel-not-showing-up/30926625#30926625); [example](https://stackoverflow.com/questions/72063606/how-to-create-a-pagination-in-java-swing/72065840#72065840) – MadProgrammer Jun 01 '22 at 02:38
-
1Reading a file into a `HashMap` isn't "hard", but a lot depends on structure of the file, so it becomes "to broad" a question for this context. Instead, you should start by looking [Basic I/O](https://docs.oracle.com/javase/tutorial/essential/io/). Having said that, I'd consider storing the questions in some kind structured format, like XML or JSON as this will help "reduce" the parsing overhead (reducing it one area might increase some of the complexity in other areas, but you're allowing the structure to be some what self documenting and parsing) – MadProgrammer Jun 01 '22 at 02:40
-
@MadProgrammer You are correct. Reading a file into a HashMap is not hard and I have already done that. The part that I am stuck on is how do I get the contents inside that HashMap on to my GUI. I would like the question and the multiple choice answers on different JLabels and JButtons. – hightestmid Jun 01 '22 at 02:42
-
1I've provide 4 runnable examples which should provide you with a baseline jumping off point. You'd be surprised how often people want to write "multiple choose quiz like programs" around here. Remember though, you're working in an Object Oriented language. `HashMap` is okay, but I'd be getting your question/answer data into its own object structure, this will make your life infinitely easier in the long run – MadProgrammer Jun 01 '22 at 02:45