53
53
import java .util .ArrayList ;
54
54
import java .util .MissingResourceException ;
55
55
import java .util .Vector ;
56
+ import java .util .logging .Logger ;
56
57
57
58
import javax .swing .AbstractAction ;
58
59
import javax .swing .Action ;
98
99
*/
99
100
public class SwingSet2 extends JPanel {
100
101
102
+ private static final Logger LOG = Logger .getLogger (SwingSet2 .class .getName ());
103
+
101
104
String [] demos = {
102
105
"ButtonDemo" ,
103
106
"ColorChooserDemo" ,
@@ -152,9 +155,9 @@ void loadDemos() {
152
155
private static final int PREFERRED_WIDTH = 720 ;
153
156
private static final int PREFERRED_HEIGHT = 640 ;
154
157
155
- // Box spacers
156
- private Dimension HGAP = new Dimension (1 ,5 );
157
- private Dimension VGAP = new Dimension (5 ,1 );
158
+ // Box spacers (not used)
159
+ // private Dimension HGAP = new Dimension(1,5);
160
+ // private Dimension VGAP = new Dimension(5,1);
158
161
159
162
// A place to hold on to the visible demo
160
163
private DemoModule currentDemo = null ;
@@ -788,35 +791,32 @@ public void setDemo(DemoModule demo) {
788
791
* Bring up the SwingSet2 demo by showing the frame (only
789
792
* applicable if coming up as an application, not an applet);
790
793
*/
791
- public void showSwingSet2 () {
792
- if (!isApplet () && getFrame () != null ) {
793
- // put swingset in a frame and show it
794
- JFrame f = getFrame ();
795
- f .setTitle (getString ("Frame.title" ));
796
- f .getContentPane ().add (this , BorderLayout .CENTER );
797
- f .pack ();
798
-
799
- Rectangle screenRect = f .getGraphicsConfiguration ().getBounds ();
800
- Insets screenInsets = Toolkit .getDefaultToolkit ().getScreenInsets (
801
- f .getGraphicsConfiguration ());
802
-
803
- // Make sure we don't place the demo off the screen.
804
- int centerWidth = screenRect .width < f .getSize ().width ?
805
- screenRect .x :
806
- screenRect .x + screenRect .width /2 - f .getSize ().width /2 ;
807
- int centerHeight = screenRect .height < f .getSize ().height ?
808
- screenRect .y :
809
- screenRect .y + screenRect .height /2 - f .getSize ().height /2 ;
810
-
811
- centerHeight = centerHeight < screenInsets .top ?
812
- screenInsets .top : centerHeight ;
813
-
814
- f .setLocation (centerWidth , centerHeight );
815
- f .show ();
816
- numSSs ++;
817
- swingSets .add (this );
818
- }
819
- }
794
+ public void showSwingSet2 () {
795
+ if (!isApplet () && getFrame () != null ) {
796
+ // put swingset in a frame and show it
797
+ JFrame f = getFrame ();
798
+ f .setTitle (getString ("Frame.title" ));
799
+ f .getContentPane ().add (this , BorderLayout .CENTER );
800
+ f .pack ();
801
+
802
+ Rectangle screenRect = f .getGraphicsConfiguration ().getBounds ();
803
+ Insets screenInsets = Toolkit .getDefaultToolkit ().getScreenInsets (f .getGraphicsConfiguration ());
804
+
805
+ // Make sure we don't place the demo off the screen.
806
+ int centerWidth = screenRect .width < f .getSize ().width ? screenRect .x
807
+ : screenRect .x + screenRect .width / 2 - f .getSize ().width / 2 ;
808
+ int centerHeight = screenRect .height < f .getSize ().height ? screenRect .y
809
+ : screenRect .y + screenRect .height / 2 - f .getSize ().height / 2 ;
810
+
811
+ centerHeight = centerHeight < screenInsets .top ? screenInsets .top : centerHeight ;
812
+
813
+ f .setLocation (centerWidth , centerHeight );
814
+ // f.show(); // Deprecated. As of JDK version 1.5, replaced by setVisible(boolean).
815
+ f .setVisible (true );
816
+ numSSs ++;
817
+ swingSets .add (this );
818
+ }
819
+ }
820
820
821
821
// *******************************************************
822
822
// ****************** Utility Methods ********************
@@ -826,15 +826,18 @@ public void showSwingSet2() {
826
826
* Loads a demo from a classname
827
827
*/
828
828
void loadDemo (String classname ) {
829
+ LOG .info (classname );
829
830
setStatus (getString ("Status.loading" ) + getString (classname + ".name" ));
830
831
DemoModule demo = null ;
831
832
try {
832
833
// Class demoClass = Class.forName(SwingSet2.class.getPackage().getName() + "." + classname);
833
- Class demoClass = Class .forName (classname );
834
- Constructor demoConstructor = demoClass .getConstructor (new Class []{SwingSet2 .class });
834
+ Class <?> demoClass = Class .forName (classname ); // throws ClassNotFoundException
835
+ Constructor <?> demoConstructor = demoClass .getConstructor (new Class []{SwingSet2 .class }); // throws NoSuchMethodException, SecurityException
835
836
demo = (DemoModule ) demoConstructor .newInstance (new Object []{this });
837
+ // throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
836
838
addDemo (demo );
837
839
} catch (Exception e ) {
840
+ LOG .warning ("Error occurred loading demo: " + classname );
838
841
System .out .println ("Error occurred loading demo: " + classname );
839
842
}
840
843
}
0 commit comments