In my game im currently working on a basic main menu and im looking for a few things.
Currently the only way to see which Jslider is which is by hovering over it.. any suggestions?
When i change the JSlider brightness or the JSlider audio it doesnt actualy update until i switch tabs and return.
When i close the game and reopen it the settings return to default. how to create a variable to preserve settings?
all code is here https://github.com/FeatheredOrcian/Kingdomcraft.git
if you would rather just see the class that the code is partaining to https://github.com/FeatheredOrcian/Kingdomcraft/blob/master/Kingdomcraft/src/com/pointlight/kingdomcraft/render/Render.java
thx
*As MadProgrammer mentioned in the comments. Avoid using setBounds, setSize or setLocation. Please review Layout Managers. The only reason I kept them in the below code is so you could see how to implement the suggestions to the 3 questions you asked.
Below is an example of the code changes that I mentioned above. Good luck!
settings.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
remove(createWorld);
remove(addServer);
repaint();
// Get stored preferences and specific default values if they
// do not exist
final Preferences prefs = Preferences.userNodeForPackage(Render.class);
soundLevel = prefs.getInt("SOUND_LEVEL", 50);
lightLevel = prefs.getInt("LIGHT_LEVEL", 50);
// Add sound label
JLabel soundLabel = new JLabel("Sound: ");
soundLabel.setBounds(170, 110, 150, 35);
soundLabel.setForeground(Color.white);
add(soundLabel);
add(sound);
sound.setBounds(210, 110, 150, 35);
sound.setMinimum(0);
sound.setMaximum(100);
sound.setValueIsAdjusting(true);
sound.setValue(soundLevel);
sound.setToolTipText("Audio: " + soundLevel + "%");
sound.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
soundLevel = sound.getValue();
// Update tooltip value
sound.setToolTipText("Audio: " + soundLevel + "%");
// Save sound value in pref
prefs.putInt("SOUND_LEVEL", soundLevel);
}
});
// Add light label
JLabel lightLabel = new JLabel("Light: ");
lightLabel.setBounds(370, 110, 150, 35);
lightLabel.setForeground(Color.white);
add(lightLabel);
add(light);
light.setBounds(405, 110, 150, 35);
light.setMinimum(0);
light.setMaximum(100);
light.setValueIsAdjusting(true);
light.setValue(lightLevel);
light.setToolTipText("Brightness: " + lightLevel + "%");
light.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
lightLevel = light.getValue();
// Update tooltip value
light.setToolTipText("Brightness: " + lightLevel + "%");
// Save light value in pref
prefs.putInt("LIGHT_LEVEL", lightLevel);
}
});
}
});