|
-
Dec 14th, 2007, 07:19 AM
#1
Thread Starter
New Member
Close a frame from another frame
Like the title says, I want to close a frame while i'm inside another frame.
I've got 2 frames. Frame 1 is called Create and Frame 2 is called Manual.
Inside Frame 1 is a button that should close Frame 2.
This is the piece of code for the button that should close Frame 2.
Code:
class btnHandleidingUitHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Handleiding.setVisible(false);
}
}
For some odd reason this doesn't work. Anyone out there that can help me with this?
-
Dec 14th, 2007, 12:10 PM
#2
Re: Close a frame from another frame
Try using JFrame.dispose() method. it's inherited from the Window class.
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Dec 14th, 2007, 12:13 PM
#3
Re: Close a frame from another frame
here is an example:
Code:
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Test {
public static void main(String args[]) {
JFrame src = new JFrame();
JButton btnOpen = new JButton("Open new");
final JFrame dest = new JFrame();
dest.setSize(100, 100);
JButton btnClose = new JButton("Close it");
btnOpen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dest.setVisible(true);
}
});
btnClose.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dest.dispose();
}
});
src.getContentPane().add(btnOpen, BorderLayout.NORTH);
src.getContentPane().add(btnClose, BorderLayout.SOUTH);
src.setSize(200, 200);
src.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
src.setVisible(true);
}
}
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Dec 15th, 2007, 08:27 AM
#4
Thread Starter
New Member
Re: Close a frame from another frame
Ahh yes, I see. Thanks a lot! That helped me on my way.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|