This site requires JavaScript, please enable it in your browser!
Greenfoot back
Rudolf
Rudolf wrote ...

2014/4/23

How to get an OK Button?

Rudolf Rudolf

2014/4/23

#
Dear Programmers, I do have a window with an OK button in it to save the config in the labels that I write in. But when I klick on the Button greenfoot is completely rebooting when I use system.exit. How could I save the Config without rebooting:)
lordhershey lordhershey

2014/4/23

#
Don't use System.exit - You are killing all of the process threads and the like by telling the Java VM to exit.
Rudolf Rudolf

2014/4/24

#
Ah, are there any other options Like dispose or so? I try it also with setvisible (false) but it doesnt work too.
danpost danpost

2014/4/24

#
You will have to see what methods are available in the class of the object you are working with.
lordhershey lordhershey

2014/4/24

#
Does this button spawn in an external frame?
Rudolf Rudolf

2014/4/24

#
@Danpost, are you meaning this? @lodhersey, no it didn´t work anywhere. I think its wrong :(
danpost danpost

2014/4/24

#
Right click on the actor and select 'Inspect'. Then report back what the top line (title) reads.
Rudolf Rudolf

2014/4/25

#
That´s what I have in my top line.
danpost danpost

2014/4/25

#
What class does the Computer class extend
Rudolf Rudolf

2014/4/26

#
The Computer extends Actor.
danpost danpost

2014/4/26

#
You are showing a lot of images. How come you have not shown the window with the OK button? That, and you have not shown any code, either. What code are you using for when the button is clicked?
Rudolf Rudolf

2014/4/27

#
I youse this code for the Windoe with the OK Button.
JDialog meinJDialog = new JDialog(new javax.swing.JFrame(), true);

        meinJDialog.setTitle("Einstellungen");
        meinJDialog.setSize(1000,300);

        meinJDialog.setLayout( new GridLayout( 0, 4, 10, 5) );
        meinJDialog.add (new JLabel (" PC "+CO));
        meinJDialog.add (new JLabel ());
        meinJDialog.add (new JLabel ());
        meinJDialog.add (new JLabel ());

        meinJDialog.add (new JLabel (" IP Adresse"));
        meinJDialog.add (new JLabel (" Netzmaske"));
        meinJDialog.add (new JLabel (" Gateway"));
        meinJDialog.add (new JLabel (" Schnittstelle"));
        
        JTextField text_1 = new JTextField (11);
        meinJDialog.add (text_1);
        JTextField text_2 = new JTextField (11);
        meinJDialog.add (text_2);
        JTextField text_3 = new JTextField (11);
        meinJDialog.add (text_3);
        JTextField text_4 = new JTextField (11);
        meinJDialog.add (text_4);

        meinJDialog.add (new JLabel ());
        meinJDialog.add (new JLabel ());
        meinJDialog.add (new JLabel ());

        JButton button_ok = new JButton("OK");              //einen neuen Button mit der Aufschrift OK anlegen
        
        button_ok.addActionListener(new java.awt.event.ActionListener() {
                // Beim Drücken des Menüpunktes wird actionPerformed aufgerufen
                public void actionPerformed(java.awt.event.ActionEvent e) {
                    // Dateiauswahldialog wird erzeugt...
                    
                    System.exit(0);
                }
            });
        meinJDialog.add (button_ok);                        //den Button zum Fenster hinzufuegen 
        meinJDialog.pack();                                 //bewirkt, dass das Dialog die minimale Grösse bei optimaler Anordnung 
                                                            //der in ihm enthaltenen Komponenten bekommt
        meinJDialog.setResizable(false);                    //Fenster kann nicht verändert werden
        meinJDialog.setLocationRelativeTo(null);            //Fenster wird zentriert
        meinJDialog.setVisible(true);                       //Fenster wird sichtbar gemacht 
       
    }
        //meinJDialog.setVisible(true);
    
    
    public void status (){
       
        meinJDialog.setVisible(false);
    }
danpost danpost

2014/4/27

#
Maybe the last method in this example might help.
You need to login to post a reply.