|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.examples.modules.testforms; import java.awt.*; import java.awt.event.*; import java.io.IOException; import javax.swing.*; import org.openide.execution.*; /** Somehow handles a class present in the Repository by "running" it. * * @author Jesse Glick */ public class TestFormExecutor extends ThreadExecutor { public TestFormExecutor () { } protected void checkClass (Class clazz) throws IOException { try { // Just check that there is nothing seriously wrong with the file, // e.g. totally inappropriate type of class, etc. Component thing = (Component) clazz.newInstance (); } catch (Exception e) { throw new IOException(e.toString()); } } protected void executeClass (Class clazz, String[] args) { try { // Actually do something with this class, e.g.: System.err.println ("Starting form -->"); // shown on OutputWindow Component thing = (Component) clazz.newInstance (); // Any calls made in clazz to System.err, etc., will go to OutputWindow automatically: Window win; if (thing instanceof Window) { win = (Window) thing; } else { JFrame frame = new JFrame ("Testing " + clazz.getName ()); frame.getContentPane ().setLayout (new BorderLayout ()); frame.getContentPane ().add (thing, BorderLayout.CENTER); win = frame; } final Object holdOn = new Object (); win.addWindowListener (new WindowAdapter () { public void windowClosing (WindowEvent ev) { synchronized (holdOn) { holdOn.notifyAll (); } } }); win.pack (); win.show (); synchronized (holdOn) { holdOn.wait (); } System.err.println ("<-- and ending."); } catch (Exception e) { // Will actually go to the OutputWindow automatically: e.printStackTrace (); } } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.