home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-10-10 | 1.7 KB | 85 lines |
- // TestApplet.java
- //
- // Created 09/25/96
- //
- // (C)Copyright 1996 Microsoft Corporation, All rights reserved.
- //
-
- import java.applet.*;
- import java.awt.*;
- import java.io.PrintStream;
-
-
- public
- class TestApplet extends Applet
- {
- protected GridBagLayout grid;
- protected GridBagConstraints c;
- protected TextArea ta;
- protected PrintStream out;
- boolean redirect = true;
-
-
- // By default, all applet output will be redirected into a text area.
-
- public void init ()
- {
- TextArea ta = new TextArea();
- ta.setEditable(false);
- add(ta);
- out = new PrintStream(new AppletOutputStream(ta), true);
-
- if (redirect)
- {
- System.out = System.err = out;
- }
- }
-
-
- public TestApplet ()
- {
- grid = new GridBagLayout();
- setLayout(grid);
- c = new GridBagConstraints();
- c.fill = GridBagConstraints.BOTH;
- c.weightx = 1;
- c.weighty = 1;
- }
-
-
- public TestApplet (boolean i_redirect)
- {
- this();
- redirect = i_redirect;
- }
-
-
- // Make sure all components are added with proper constraints.
-
- public Component add (Component comp)
- {
- grid.setConstraints(comp,c);
- return super.add(comp);
- }
-
-
- public static void main (TestApplet applet, String title, String[] args)
- {
- try
- {
- Frame f = new TestFrame(title);
- f.add("Center",applet);
- applet.init();
- f.pack();
- f.show();
- applet.start();
- }
- catch (Throwable e)
- {
- System.err.println("main: error: "+e);
- e.printStackTrace();
- }
- }
- }
-
-