Home

A scripted ActionListener Interface

CallScriptedActionHandler.java - Link a button to a scripted ActionListener
import javax.swing.*;
import java.awt.event.ActionListener;
import bsh.Interpreter;

public class CallScriptedActionHandler {
    public static void main( String [] args ) throws Exception {

        JButton button = new JButton("MyButton");
        button.addActionListener( 
            (ActionListener)new Interpreter().source("actionHandler.bsh") );

        JFrame f = new JFrame();
        f.getContentPane().add( button );
        f.show();
    }
}

actionHandler.bsh - The scripted ActionListener
import java.awt.event.ActionListener;

actionPerformed( e ) {
    print("Button Pressed: " + e);
}

return (ActionListener)this;