Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #3648 > unrolled thread
| Started by | "Hendrik Maryns" <hendrik.maryns@THRWHITE.remove-dii-this> |
|---|---|
| First post | 2011-04-27 15:46 +0000 |
| Last post | 2011-04-27 15:46 +0000 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.java.gui
Proper way to handle wind "Hendrik Maryns" <hendrik.maryns@THRWHITE.remove-dii-this> - 2011-04-27 15:46 +0000
Re: Proper way to handle "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:46 +0000
Re: Proper way to handle "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:46 +0000
| From | "Hendrik Maryns" <hendrik.maryns@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:46 +0000 |
| Subject | Proper way to handle wind |
| Message-ID | <g387uc$b0a$1@newsserv.zdv.uni-tuebingen.de> |
To: comp.lang.java.gui
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
I have an applications which lets users edit some stuff in a main field.
~ If the user closes it down without saving, I want to ask him. For this
I created a save Action and a quit Action which calls the save action if
necessary. I then set
result.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
on the main frame and add a WindowListener:
~ frame.addWindowListener(new WindowAdapter() {
~ @Override
~ public void windowClosing(final WindowEvent evt) {
~ // TODO: this seems a little bit like a hack, although it works.
Maybe the other way round: have the
~ // quit action close the window and handle saving here?
~ quitAction.actionPerformed(new ActionEvent(this,
ActionEvent.ACTION_FIRST, "close")); //$NON-NLS-1$
~ }
~ @Override
~ public void windowClosed(final WindowEvent evt) {
~ // store the size of the window to restore it on next use
~ getUserPrefs().putInt(widthPrefKey, frame.getWidth());
~ getUserPrefs().putInt(heightPrefKey, frame.getHeight());
~ getUserPrefs().putInt(xPrefKey, frame.getX());
~ getUserPrefs().putInt(yPrefKey, frame.getY());
~ }
~ });
Since the quit action calls System.exit(0), windowClosed() is not
executed and the size and location of the window are not remembered.
OTOH windowClosed seems like the proper place to put that stuff.
I could simply move it up before where I call the quit action, but this
is not satisfactory either. As you can see from the comments, I think
it is a bit awkward to call the quit action like that.
I'd be happy with some suggestions on how you'd solve this.
Cheers, H.
- --
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org
iD8DBQFIV6MMe+7xMGD3itQRAvJYAJ49ArFa/Ukl5r9zS9e4gkNpUoDDQgCeIiAb
3EZSBx2DOVaOq3pT4PEDlb8=
=J/Tl
-----END PGP SIGNATURE-----
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [next] | [standalone]
| From | "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:46 +0000 |
| Subject | Re: Proper way to handle |
| Message-ID | <e1862afa-e86f-40b2-a4d5-60f7ccbd5ec2@a32g2000prf.googlegroups.com> |
| In reply to | #3648 |
To: comp.lang.java.gui On Jun 17, 9:42=A0pm, Hendrik Maryns <gtw37b...@sneakemail.com> wrote: =2E.. > I have an applications which lets users edit some stuff in a main field. > ~ If the user closes it down without saving, I want to ask him. =A0 What happens of the system shuts down without the program having been closed? For that, see addShutDownHoook(Thread). <http://java.sun.com/javase/6/docs/api/java/lang/ Runtime.html#method_summary> -- Andrew Thompson http://pscode.org/ --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:46 +0000 |
| Subject | Re: Proper way to handle |
| Message-ID | <5qej54l66lercc240lrsplfh5361dr0jid@4ax.com> |
| In reply to | #3648 |
To: comp.lang.java.gui
On Tue, 17 Jun 2008 13:42:04 +0200, Hendrik Maryns
<gtw37bn02@sneakemail.com> wrote, quoted or indirectly quoted someone
who said :
>I have an applications which lets users edit some stuff in a main field.
>~ If the user closes it down without saving, I want to ask him. For this
>I created a save Action and a quit Action which calls the save action if
>necessary.
Here are my two typical shutdowns one for AWT and one for SWING that
let me run an Applet as an application.
/*
Converts a Applet into an Application.
copyright (c) 2006-2008 Roedy Green, Canadian Mind Products
may be copied and used freely for any purpose but military.
Roedy Green
Canadian Mind Products
#101 - 2536 Wark Street
Victoria, BC Canada
V8T 4G8
tel: (250) 361-9093
roedy g at mindprod dotcom
http://mindprod.com
Version History
1.0 2006-03-07 initial version.
*/
package com.mindprod.common11;
import java.applet.Applet;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/**
* Converts a Applet into an Application.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0, 2006-03-07 Created with IntelliJ IDEA.
*/
public final class Hybrid
{
// -------------------------- PUBLIC STATIC METHODS
--------------------------
/**
* Fire up the Applet as an application
*
* @param title title for frame usually TITLE_STRING+
" " + VERSION_STRING
* @param applicationWidth width of frame, usually APPLET_WIDTH
* @param applicationHeight height of frame body, usually
APPLET_HEIGHT
*/
public static void fireup( final Applet applet,
final String title,
final int applicationWidth,
final int applicationHeight )
{
final Frame frame = new Frame( title );
// allow some extra room for the frame title bar.
frame.setSize( applicationWidth + 16, applicationHeight + 36
);
frame.addWindowListener( new WindowAdapter()
{
/**
* Handle request to shutdown.
*
* @param e event giving details of closing.
*/
public void windowClosing( WindowEvent e )
{
applet.stop();
applet.destroy();
System.exit( 0 );
}// end WindowClosing
}// end anonymous class
);// end addWindowListener line
frame.add( applet );
applet.init();
frame.validate();
frame.setVisible( true );
applet.start();
}
}
----------------------------------------------------------------------------------------------------
/*
Converts a JApplet into an Application.
copyright (c) 2005-2008 Roedy Green, Canadian Mind Products
may be copied and used freely for any purpose but military.
Roedy Green
Canadian Mind Products
#101 - 2536 Wark Street
Victoria, BC Canada
V8T 4G8
tel: (250) 361-9093
roedy g at mindprod dotcom
http://mindprod.com
Version History
1.0 2006-03-07 initial version.
*/
package com.mindprod.common13;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/**
* Converts a JApplet into an Application.
* <p/>
* Created with IntelliJ IDEA.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0, 2006-03-07
*/
public final class HybridJ
{
// -------------------------- PUBLIC STATIC METHODS
--------------------------
/**
* Fire up the JApplet as an application
*
* @param title title for frame usually TITLE_STRING+
" " + VERSION_STRING
* @param applicationWidth width of frame, usually APPLET_WIDTH
* @param applicationHeight height of frame body, usually
APPLET_HEIGHT
*/
public static void fireup( final JApplet applet,
final String title,
final int applicationWidth,
final int applicationHeight )
{
// fire up JApplet on the Swing Thread
SwingUtilities.invokeLater( new Runnable()
{
/**
* do all swing work on the swing thread.
*/
public void run()
{
JFrame.setDefaultLookAndFeelDecorated( true );
final JFrame frame = new JFrame( title );
frame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE
);
// allow some extra room for the frame title bar.
frame.setSize( applicationWidth + 22, applicationHeight +
32 );
frame.addWindowListener( new WindowAdapter()
{
/**
* Handle request to shutdown.
*
* @param e event giving details of closing.
*/
public void windowClosing( WindowEvent e )
{
applet.stop();
applet.destroy();
System.exit( 0 );
}// end WindowClosing
}// end anonymous class
);// end addWindowListener line
frame.getContentPane().add( applet );
applet.init();
// yes frame, not contentpane.
frame.validate();
frame.setVisible( true );
applet.start();
}// end run
}// end runnable
);
}
}
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.gui
csiph-web