Skip to content

Commit 59c90d8

Browse files
committed
eclipse launch + replace deprecated show()
LOG TODO: remove deprecated JApplet, Applet
1 parent 5348d58 commit 59c90d8

File tree

3 files changed

+77
-49
lines changed

3 files changed

+77
-49
lines changed

RUN SwingSet 2.launch

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
3+
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
4+
<listEntry value="/SwingSet2-demos/src/main/java/SwingSet2.java"/>
5+
</listAttribute>
6+
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
7+
<listEntry value="1"/>
8+
</listAttribute>
9+
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/>
10+
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_EXCLUDE_TEST_CODE" value="true"/>
11+
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_SHOW_CODEDETAILS_IN_EXCEPTION_MESSAGES" value="true"/>
12+
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_CLASSPATH_ONLY_JAR" value="false"/>
13+
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="SwingSet2"/>
14+
<stringAttribute key="org.eclipse.jdt.launching.MODULE_NAME" value="SwingSet2-demos"/>
15+
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="SwingSet2-demos"/>
16+
</launchConfiguration>

src/main/java/DemoModule.java

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,36 @@
3030
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3131
*/
3232

33-
import javax.swing.*;
34-
import javax.swing.event.*;
35-
import javax.swing.text.*;
36-
import javax.swing.border.*;
37-
import javax.swing.colorchooser.*;
38-
import javax.swing.filechooser.*;
39-
import javax.accessibility.*;
40-
41-
import java.awt.*;
42-
import java.awt.event.*;
43-
import java.beans.*;
44-
import java.util.*;
45-
import java.io.*;
46-
import java.applet.*;
47-
import java.net.*;
33+
import java.awt.BorderLayout;
34+
import java.awt.Dimension;
35+
import java.io.BufferedReader;
36+
import java.io.InputStream;
37+
import java.io.InputStreamReader;
38+
import java.net.URL;
39+
40+
import javax.swing.BoxLayout;
41+
import javax.swing.Icon;
42+
import javax.swing.ImageIcon;
43+
import javax.swing.JApplet;
44+
import javax.swing.JFrame;
45+
import javax.swing.JPanel;
46+
import javax.swing.UIManager;
47+
import javax.swing.border.Border;
48+
import javax.swing.border.CompoundBorder;
49+
import javax.swing.border.EmptyBorder;
50+
import javax.swing.border.SoftBevelBorder;
4851

4952
/**
5053
* A generic SwingSet2 demo module
5154
*
5255
* @author Jeff Dinkins
5356
*/
57+
/*
58+
TODO remove JApplet, Applet Deprecated since = "9" forRemoval
59+
Applet extends Panel
60+
JApplet extends Applet implements Accessible, RootPaneContainer, TransferHandler.HasGetTransferHandler
61+
==> TODO : DemoModule extends Panel implements Accessible, RootPaneContainer, TransferHandler.HasGetTransferHandler
62+
*/
5463
public class DemoModule extends JApplet {
5564

5665
// The preferred size of the demo

src/main/java/SwingSet2.java

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import java.util.ArrayList;
5454
import java.util.MissingResourceException;
5555
import java.util.Vector;
56+
import java.util.logging.Logger;
5657

5758
import javax.swing.AbstractAction;
5859
import javax.swing.Action;
@@ -98,6 +99,8 @@
9899
*/
99100
public class SwingSet2 extends JPanel {
100101

102+
private static final Logger LOG = Logger.getLogger(SwingSet2.class.getName());
103+
101104
String[] demos = {
102105
"ButtonDemo",
103106
"ColorChooserDemo",
@@ -152,9 +155,9 @@ void loadDemos() {
152155
private static final int PREFERRED_WIDTH = 720;
153156
private static final int PREFERRED_HEIGHT = 640;
154157

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);
158161

159162
// A place to hold on to the visible demo
160163
private DemoModule currentDemo = null;
@@ -788,35 +791,32 @@ public void setDemo(DemoModule demo) {
788791
* Bring up the SwingSet2 demo by showing the frame (only
789792
* applicable if coming up as an application, not an applet);
790793
*/
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+
}
820820

821821
// *******************************************************
822822
// ****************** Utility Methods ********************
@@ -826,15 +826,18 @@ public void showSwingSet2() {
826826
* Loads a demo from a classname
827827
*/
828828
void loadDemo(String classname) {
829+
LOG.info(classname);
829830
setStatus(getString("Status.loading") + getString(classname + ".name"));
830831
DemoModule demo = null;
831832
try {
832833
// 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
835836
demo = (DemoModule) demoConstructor.newInstance(new Object[]{this});
837+
// throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
836838
addDemo(demo);
837839
} catch (Exception e) {
840+
LOG.warning("Error occurred loading demo: " + classname);
838841
System.out.println("Error occurred loading demo: " + classname);
839842
}
840843
}

0 commit comments

Comments
 (0)