[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
JFrame DefaultCloseOperation CLOSE_ON_EXIT fixlet
From: |
Mark Wielaard |
Subject: |
JFrame DefaultCloseOperation CLOSE_ON_EXIT fixlet |
Date: |
Thu, 15 Apr 2004 11:30:27 +0200 |
Hi,
Noticed that JFrame get/setDefaultCloseOperation weren't public and
didn't do the right default thing. So I fixed them and added the correct
argument checking to setDefaultCloseOperation.
2004-04-15 Mark Wielaard <address@hidden>
* javax/awt/JFrame.java (close_action): Default to HIDE_ON_CLOSE.
(getDefaultCloseOperation): Make public.
(processWindowEvent): Call System.exit(0) when HIDE_ON_CLOSE set.
(setDefaultCloseOperation): Make public. Check argument. Add API doc.
Committed to classpath CVS.
Could someone with a recent gcj-gui-branch checkout add it there?
Thanks,
Mark
Index: javax/swing/JFrame.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JFrame.java,v
retrieving revision 1.8
diff -u -r1.8 JFrame.java
--- javax/swing/JFrame.java 14 Feb 2004 21:42:56 -0000 1.8
+++ javax/swing/JFrame.java 15 Apr 2004 09:24:30 -0000
@@ -66,7 +66,7 @@
protected AccessibleContext accessibleContext;
- private int close_action = EXIT_ON_CLOSE;
+ private int close_action = HIDE_ON_CLOSE;
/***************************************************
@@ -192,7 +192,7 @@
return accessibleContext;
}
- int getDefaultCloseOperation()
+ public int getDefaultCloseOperation()
{ return close_action; }
@@ -212,7 +212,7 @@
{
case EXIT_ON_CLOSE:
{
- System.exit(1);
+ System.exit(0);
break;
}
case DISPOSE_ON_CLOSE:
@@ -241,8 +241,30 @@
}
}
-
- void setDefaultCloseOperation(int operation)
- { close_action = operation; }
+ /**
+ * Defines what happens when this frame is closed. Can be one off
+ * <code>EXIT_ON_CLOSE</code>,
+ * <code>DISPOSE_ON_CLOSE</code>,
+ * <code>HIDE_ON_CLOSE</code> or
+ * <code>DO_NOTHING_ON_CLOSE</code>.
+ * The default is <code>HIDE_ON_CLOSE</code>.
+ * When <code>EXIT_ON_CLOSE</code> is specified this method calls
+ * <code>SecurityManager.checkExit(0)</code> which might throw a
+ * <code>SecurityException</code>. When the specified operation is
+ * not one of the above a <code>IllegalArgumentException</code> is
+ * thrown.
+ */
+ public void setDefaultCloseOperation(int operation)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null && operation == EXIT_ON_CLOSE)
+ sm.checkExit(0);
+
+ if (operation != EXIT_ON_CLOSE && operation != DISPOSE_ON_CLOSE
+ && operation != HIDE_ON_CLOSE && operation != DO_NOTHING_ON_CLOSE)
+ throw new IllegalArgumentException("operation = " + operation);
+
+ close_action = operation;
+ }
}
signature.asc
Description: This is a digitally signed message part
- JFrame DefaultCloseOperation CLOSE_ON_EXIT fixlet,
Mark Wielaard <=