Re: Entering a time into textbox
Salad <oil@vinegar.com> writes:
I am doing a homework assignment. Although the assignment says to pass
parameters to a method, I wanted to extend the capabilities
Then you are not doing the assignment anymore. So, I would
pass in also an unextended solution.
How do I permit overwrite?
Make the default text selected initially?
3) Same holds true with the Exit button. If I use the mouse
on the Exit button, the window closes. But if I tab to the
Exit button then press Enter, nothing.
The behavior of Keys in Swing depends on the LAF. See:
http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/doc-files/Key-Index.html
You can overwrite this by you custom behavior, but this might
confuse user who expect the application to behave according to
the default key interpretation of the LAF chosen.
You do not know whether you custom behaviour might conflict
with a LAF (including future LAFs not available now for tests).
5) I used System.exit(0) to "close" the window. Is that what one does
to close windows?
To ?close? a window, it usually is hidden.
?System.exit( 0 )? will abort the entire process not just
close a window.
Some GUI components can be ?disposed?.
I have observed that the EDT and the whole process will
terminate without calling ?System.exit( 0 )? after I have
disposed all GUI components that I have created before. As I
love a tidy cleanup, this seems to be the most elegant way to
me, since a failure of the application to terminate on closing
the last window immediatly reveals that the resource
management is faulty. However, this takes care. (That's why I
like it: It enforces care!)
This is shown in the following example.
It uses
frame.setDefaultCloseOperation
( javax.swing.JFrame.DO_NOTHING_ON_CLOSE );
and it does not call ?java.lang.System.exit?.
Still the process ends when the window is closed, due to
?frame.dispose()?.
(When replying to my post, please do not quote my complete
post, but only those parts you directly refer to. Especially,
please do not quote the complete source code.)
public class Main
{ public static void main( final java.lang.String[] args )
{ javax.swing.SwingUtilities.invokeLater( new FrameController() ); }}
class FrameView
{ FrameController controller;
javax.swing.JFrame frame = null;
public FrameView()
{ frame = new javax.swing.JFrame( "Dispose Example by Stefan Ram" );
frame.setDefaultCloseOperation
( javax.swing.JFrame.DO_NOTHING_ON_CLOSE );
frame.pack(); frame.setVisible( true ); }
public void setController
( final FrameController controller )
{ this.controller = controller;
this.controller.setView( this );
frame.addWindowListener( this.controller ); }
public void releaseController()
{ frame.removeWindowListener( this.controller );
this.controller.releaseView();
this.controller = null; }
public void dispose()
{ frame.dispose(); frame = null; }}
class FrameController
implements java.lang.Runnable,
java.awt.event.WindowListener
{ FrameView view = null;
public void setView( final FrameView view )
{ this.view = view; }
public void releaseView()
{ this.view = null; }
public void run()
{ FrameView view = new FrameView();
view.setController( this ); }
public void windowClosing
( final java.awt.event.WindowEvent e )
{ FrameView view = this.view;
view.releaseController();
view.dispose(); }
public void windowOpened( final java.awt.event.WindowEvent e ){}
public void windowDeactivated( final java.awt.event.WindowEvent e ){}
public void windowDeiconified( final java.awt.event.WindowEvent e ){}
public void windowIconified( final java.awt.event.WindowEvent e ){}
public void windowActivated( final java.awt.event.WindowEvent e ){}
public void windowClosed( final java.awt.event.WindowEvent e ){} }