Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Campbell Ritchie
Ron McLeod
Junilu Lacar
Liutauras Vilda
Sheriffs:
Paul Clapham
Jeanne Boyarsky
Henry Wong
Saloon Keepers:
Tim Moores
Tim Holloway
Stephan van Hulst
Piet Souris
Carey Brown
Bartenders:
Jesse Duncan
Frits Walraven
Mikalai Zaikin
Forum:
Swing / AWT / SWT
opening new frame
sachin dabhade
Ranch Hand
Posts: 73
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hello all,
i have an application made in swing using frames.
i have a button on it.
what i want to do is on the click event of the button,i want to open a new frame and kill this frame.
can anybody help me how to do this??
thanks in advance.
sachin
Rene Liebmann
Ranch Hand
Posts: 196
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
here is the code you want:
import javax.swing.*; import java.awt.*; import java.awt.event.*; /** * <p>�berschrift: </p> * <p>Beschreibung: </p> * <p>Copyright: Copyright (c) 2002</p> * <p>Organisation: </p> * @author unbekannt * @version 1.0 */ public class FrameKiller extends JFrame { JToolBar jToolBar1 = new JToolBar(); JButton btnFrameHandler = new JButton(); JFrame frame = null; public FrameKiller() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } public static void main(String[] args) { FrameKiller frameKiller1 = new FrameKiller(); frameKiller1.setSize(200,200); frameKiller1.show(); } private void jbInit() throws Exception { btnFrameHandler.setText("Create Frame"); btnFrameHandler.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { btnFrameHandler_actionPerformed(e); } }); this.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(WindowEvent e) { this_windowClosing(e); } }); this.getContentPane().add(jToolBar1, BorderLayout.NORTH); jToolBar1.add(btnFrameHandler, null); } void btnFrameHandler_actionPerformed(ActionEvent e) { if (frame == null){ frame = new JFrame("Kill me"); frame.setSize(200,200); frame.show(); this.btnFrameHandler.setText("Kill Frame"); } else{ frame.dispose(); frame = null; this.btnFrameHandler.setText("Create Frame"); } } void this_windowClosing(WindowEvent e) { System.exit(0); } }
Hope this helps
Rene
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Unloading a frame
opening a frame right beneath the calling button
How i close my frame when i click in the button???
JInternal Frame Problem
Reg: Jframe
More...