Esvin Oxlaj
Esvin Oxlaj

Reputation: 11

How to save the preferences with a JButton?

I'm new to Java and I am trying to save the preferences on an option window. I am creating maps of the game with JLabel matrices. I have 3 maps, and the user will select them with a Combo box and select rounds (1 rounds,3 rounds or 5 rounds) for the game and I need to save those options being selected by the user.

This is the method for the combobox, now the this is that I don't know how to added to the botton so that it save the settings, so when the user click on New Game it will open the options that was being selected before. I'm using Menu Items. Where tab is the variable for my class Tablero.

public void itemStateChanged(ItemEvent e) {
   int selectedIndex = combobox.getSelectedIndex();
             switch(selectedIndex){
                    case 0: //small map

                          tab.matrizpeque();
                          tab.llmatrizpeque(5,8);
                                             break;
                   case 1: //med map

                          tab.matrizmed();
                          tab.llmatrizmed(8,12);
                                             break;
                  case 2: //big map

                          tab.matrizbig();
                          tab.llmatrizbig(10,15);
                                             break;
                        }    

}

Upvotes: 1

Views: 179

Answers (2)

Ashwinee K Jha
Ashwinee K Jha

Reputation: 9317

Java preferences api is the standard way to do this http://docs.oracle.com/javase/6/docs/technotes/guides/preferences/overview.html

Upvotes: 3

kasavbere
kasavbere

Reputation: 6003

You can use mysql to persist the data, that's the easier way. Another good option is an xml file. do a search for persistence with xml.

Upvotes: 0

Related Questions