tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Java Scripting > BeanShell > Simple UI

Simple UI 

BeanShell is a small, free, embeddable Java source interpreter with object scripting language features, written in Java. BeanShell is a natural scripting language for Java. This requires the library bsh-2.0b4.jar to be in classpath. The following example shows developing simple UI in beanshell script.

File Name  :  
/BEAN_SHELL001/config/simpleui.bsh 
   
// Open input popup dialog
strName = JOptionPane.showInputDialog(null, " Enter your name : ");

//implementing ActionListener interface (this - context reference)
actionPerformed(event) {
  print(event);
}

//implementing WindowListener interface
WindowListener listener = new WindowAdapter() {
  public void windowClosing(WindowEvent w) {
    System.exit(0);
  }
};

//Create button and add to frame      
button = new JButton("Click Me");
button.addActionListener(this);

frame = new JFrame("Hello " + strName);
frame.getContentPane().add(button);

frame.addWindowListener(listener);
frame.setSize(200200);
frame.setVisible(true);
   

File Name  :  
com/bethecoder/tutorials/bean_shell/UITest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.bean_shell;

import java.io.InputStreamReader;

import bsh.EvalError;
import bsh.Interpreter;

public class UITest {

  /**
   @param args
   @throws EvalError 
   */
  public static void main(String[] argsthrows EvalError {
    Interpreter interpreter = new Interpreter();  
    InputStreamReader reader = new InputStreamReader(
        UITest.class.getClassLoader()
        .getResourceAsStream("simpleui.bsh"));
    
    interpreter.eval(reader);
  }

}
   



 
  


  
bl  br