While both programs and applications can become important, it becomes confusing and useless to use them everywhere. The remainder of this section replaces them with the display framework for a swing program example:
: Show.java
//Tool for displaying Swing demos
package c13.swing;
Import java.awt.*;
Import java.awt.event.*;
Import javax.swing.*;
public class Show {public
static void
inframe (JPanel jp, int width, int height) {
String title = Jp.getclass (). toString ();
Remove the word "class":
if (Title.indexof ("class")!=-1)
title = title.substring (6);
JFrame frame = new JFrame (title);
Frame.addwindowlistener (New Windowadapter () {public
void windowclosing (WindowEvent e) {
system.exit (0);
}
});
Frame.getcontentpane (). Add (
JP, borderlayout.center);
Frame.setsize (width, height);
Frame.setvisible (True);
}
///:~
Classes that want to show their own will inherit from the JPanel and then add some visual components to themselves. Finally, they create a main () that contains the following line of programs:
Show.inframe (New MyClass (), 500, 300);
The last two arguments are the width and height of the display.
Note that the title of the JFrame is produced with Rtti.