A test for a SwixML applet.
<panel Border="EtchedBorder" Layout="BorderLayout">
<panel constraints="BorderLayout.NORTH">
<label DisplayedMnemonic="VK_E" LabelFor="tf" Columns="10">My input</label>
<textfield id="tf" Columns="10" Text="Hello World" />
</panel>
<panel constraints="BorderLayout.CENTER" Border="EtchedBorder">
<textarea id="ta" Editable="false" Rows="5" Columns="20" Text="Output text area" LineWrap="true" />
</panel>
<panel constraints="BorderLayout.SOUTH">
<button id="btn" Text="TestIt" Action="submit" />
</panel>
</panel>
import java.awt.event.ActionEvent;
import java.io.StringBufferInputStream;
import java.net.URLDecoder;
import javax.swing.AbstractAction;
import javax.swing.JApplet;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import org.swixml.SwingEngine;
public class SnippetApplet extends JApplet {
public final static String APPLET_START = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><applet size=\"320,200\">";
public final static String APPLET_END = "</applet>";
/**
* JTextField member gets instantiated through Swixml (look for id="tf" in the
* xml descriptor)
*/
public JTextField tf;
public JTextArea ta;
public AbstractAction submit = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
StringBuffer buffer = new StringBuffer();
buffer.append(tf.getText());
String resultStr = buffer.toString();
ta.setText(resultStr.toString());
return;
}
};
public void init() {
super.init();
try {
String parameterName = "fields";
String value = getParameter(parameterName);
if (value != null) {
value = URLDecoder.decode(value, "UTF-8");
}
StringBufferInputStream stream = new StringBufferInputStream(APPLET_START+value+APPLET_END);
new SwingEngine(this).insert(stream, this);
this.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
}