Hello!
I want to make a program which
1) will open a frame with a button.
2) When I press the button it will open a new frame with another button.
3)When I press the button of the second frame I want to close the second frame.
PHP Code:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Listener
implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e)
{
JFrame newFrame = new JFrame("New Frame");
String str = e.getActionCommand();
JButton button = new JButton("DEL");
button.addActionListener(this);
newFrame.add(button);
newFrame.setSize(200,200);
if(str == "OK")
{
newFrame.setVisible(true);
}
if(str.equals(button))
{
newFrame.setVisible(false);
}
}
public static void main(String[] args)
{
Listener listen = new Listener();
JFrame frame = new JFrame();
JButton button = new JButton("OK");
button.addActionListener(listen);
frame.add(button);
frame.setSize(50,150);
frame.setVisible(true);
}
}
Have done this which
1) will open a frame with a button.
2) When I press the button it will open a new frame with another button.
As you see i have tried the setVisible(false) but it don't work so here is my question. What I could use to close or set invisible the frame ? and why the setVisible(false) don't work?
Thanks in advance for your time wasting,
Kostas