jeudi 27 avril 2017

Java Checkbox Save

i Need some help with saving checkboxes, im new in this and hope i'll get some help.

What i want to do: I want to save the Settings:

if(e.getSource() == einstellung){


        JFrame meinJFrame = new JFrame();
        meinJFrame.setTitle("JRadioButton Beispiel");
        meinJFrame.setSize(400,300);
        JPanel panel = new JPanel();
        panel.setBackground(Color.BLACK);
 //Checkbox 1

        JCheckBox check = new JCheckBox("Activate Wall at the score of 500k.", false);

        panel.add(check);

      //Checkbox 2
        JCheckBox check1 = new JCheckBox ("Activate Trump Tower at the score of 1 million.", false);

        panel.add(check1);           

        meinJFrame.add(panel);
        meinJFrame.setVisible(true);

It's for a little game i am creating and i just want to save the checkboxes, so they are checked (or not) when i start the Programm again.

The full code (please do not use it for private things like using it for your own game or sth like that):

private JButton schliessen;
private JButton einstellung;
private JButton info;
private JButton ende;
private JTextField Textbox;

JCheckBox redCB, blueCB, greenCB, yellowCB;


public static void main(String[] args) throws Exception {






    frame frame = new frame("Jump Trump Menu");
    frame.setResizable(false);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400,460);
    frame.getContentPane().setBackground(Color.BLACK);  


    frame.setLayout(null);
    frame.setVisible(true);














}








public frame(String title) {

    super(title);

    schliessen = new JButton("Play");
    schliessen.setBounds(120,40,160,40);
    schliessen.addActionListener(this);
    add(schliessen);
    schliessen.setBorderPainted(false);
    schliessen.setFocusPainted(false);
    schliessen.setContentAreaFilled(true);
    schliessen.setHorizontalAlignment(JButton.CENTER);

    einstellung = new JButton("Settings");
    einstellung.setBounds(120,120,160,40);
    einstellung.addActionListener(this);
    add(einstellung);
    einstellung.setBorderPainted(false);
    einstellung.setFocusPainted(false);
    einstellung.setContentAreaFilled(true);
    einstellung.setHorizontalAlignment(JButton.CENTER);

    info = new JButton("Special Contract");
    info.setBounds(120,200,160,40);
    info.addActionListener(this);
    add(info);
    info.setBorderPainted(false);
    info.setFocusPainted(false);
    info.setContentAreaFilled(true);
    info.setHorizontalAlignment(JButton.CENTER);

    ende = new JButton("Exit");
    ende.setBounds(120,280,160,40);
    ende.addActionListener(this);
    add(ende);
    ende.setBorderPainted(false);
    ende.setFocusPainted(false);
    ende.setContentAreaFilled(true);
    ende.setHorizontalAlignment(JButton.CENTER); 

    Textbox = new JTextField("Pre Alpha 0.0.5");
    Textbox.setHorizontalAlignment(JTextField.CENTER); 
    Textbox.setBounds(120,360,160,40);
    add(Textbox);
    Textbox.setEditable (false);


}



public static void fenster(){


    JFrame fenster = new JFrame("JumpTrump");
    fenster.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    fenster.setSize(650,350);
    fenster.setVisible(true);
    fenster.add(new gui());
    fenster.setResizable(false);







    }

//public static void auswahl(){

//}



@Override
public void actionPerformed(ActionEvent e) {

    // TODO Auto-generated method stub

    if (e.getSource()== schliessen ){
        fenster();


            URL url = SoundTest.class.getResource("donald.au");
            AudioClip clip = Applet.newAudioClip(url);

            clip.play();

            clip.loop();

    }

    if (e.getSource() == info ){
        Object[] options = { "Agree", "Disagree", "Die Now"};


        if (e.getSource()== options){
            System.exit(0);
        }
    int result =    JOptionPane.showOptionDialog(null,"Programmed by Zensoran your lord and king  ! By clicking (Agree) you swear that you give your life to the holy King of Steam (Lord Gaben), by clicking (Disagree) you won't get a Steam Summer sale!","Contract",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.PLAIN_MESSAGE,null,options,options[2]);    

        if (result == JOptionPane.YES_OPTION);
        if (result == JOptionPane.NO_OPTION) System.exit(0);
        if (result == JOptionPane.CANCEL_OPTION) System.exit(0);

    }


    if(e.getSource() == einstellung){


        JFrame meinJFrame = new JFrame();
        meinJFrame.setTitle("JRadioButton Beispiel");
        meinJFrame.setSize(400,300);
        JPanel panel = new JPanel();
        panel.setBackground(Color.BLACK);
 //Checkbox 1

        JCheckBox check = new JCheckBox("Activate Wall at the score of 500k.", false);

        panel.add(check);

      //Checkbox 2
        JCheckBox check1 = new JCheckBox ("Activate Trump Tower at the score of 1 million.", false);

        panel.add(check1);           

        meinJFrame.add(panel);
        meinJFrame.setVisible(true);















    }

    if(e.getSource() == ende){

        if (JOptionPane.showConfirmDialog(null, "Are you sure you want to quit?", "WARNING",
                JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            System.exit(ERROR);
        } else {


              }
            }











}

}




Aucun commentaire:

Enregistrer un commentaire