1 
2 import org.swixml.SwingEngine;
3 
4 import javax.swing.*;
5 import java.awt.event.ActionEvent;
6 import java.net.URL;
7 
8 
9 /**
10 * The SwixmlApplet class shows how to use the SwixmlmlEngine
11 * to create JApplets.
12 * The XML descriptor needs to be referenced with an parameter like this:
13 * xml=xml/SwinxmlApplet.xml
14 * When ran locally using SUN's AppletViewer, the file needs to be made available here:
15 * C:\Temlp\xml\...
16 *
17 * @author <a href="mailto:[email protected]">Wolf Paulus</a>
18 * @version $Revision: 1.1 $
19 *
20 */
21
22public class SwixApplet extends JApplet {
23
24  /** JTextField member gets instantiated through Swixml (look for id="tf" in the xml descriptor) */
25  public JTextField tf;
26  /**
27   * Action appends a '#' to the textfields content.
28   */
29  public AbstractAction submit = new AbstractAction() {
30    public void actionPerformed( ActionEvent e ) {
31      tf.setText( tf.getText() + '#' );
32    }
33  };
34
35  public void init() {
36
37    super.init();
38    try {
39      String descriptorfile = this.getParameter( "xml" );
40      if (descriptorfile == null) {
41        descriptorfile = "xml/applet.xml";
42      }
43      new SwingEngine( this ).insert( new URL( getCodeBase(), descriptorfile ), this );
44      this.setVisible( true );
45    } catch (Exception e) {
46      e.printStackTrace();
47    }
48  }
49}
50