import com.swath.*; import com.swath.cmd.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; /** * This script shows how to create and display your own * custom parameter window. You can add any components you like. * Read more about the Java Abstract Window Toolkit (AWT) * or the Swing framework for information about how to use * the different components available. * * @author Stein * @since SWATH 1.4 */ public class ExampleScript5 extends UserDefinedScript { private Panel m_panel; private TextField m_name; private TextField m_fighters; private Button m_button; private int m_count; public String getName() { return "Example Script #5"; } public String getDescription() { return "This script shows how to create and display your own\n"+ "custom parameter window. You can add any components you like.\n\n"+ "Read more about the Java Abstract Window Toolkit (AWT)\n"+ "or the Swing framework for information about how to use\n"+ "the different components available."; } public boolean initScript() throws Exception { // Check that we are at the correct prompt if (!atPrompt(Swath.COMMAND_PROMPT)) return false; // Create a panel to add the components to m_panel = Tools.createPanel(); // Create and add two text input fields to the panel m_panel.add(new Label("Name:")); m_name = new TextField(25); m_panel.add(m_name); m_panel.add(new Label("Fighters:")); m_fighters = new TextField(10); m_panel.add(m_fighters); // Create and add a button to the panel. // When the button is pressed the text "<<< Button pressed >>>" is printed. m_button = new Button("Press Me"); m_button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { printTrace("<<< Button pressed >>>"); m_count++; } catch (Exception e) { } } }); m_panel.add(m_button); m_count = 0; // Shows the script parameter window with our new panel :) return showUserParamWindow(m_panel, 350, 200); } public boolean runScript() throws Exception { String name; int fighters; // Get and parse the data from the input fields name = m_name.getText(); try { fighters = Integer.parseInt(m_fighters.getText()); } catch (NumberFormatException e) { fighters = 0; } // Do what you want... PrintText.exec("\n"); PrintText.exec("Name....: " + name + "\n"); PrintText.exec("Fighters: " + fighters + "\n"); PrintText.exec("You pressed the button " + m_count + " times!\n"); return true; } public void endScript(boolean finished) throws Exception { // Nothing to do } }