001    package org.jdmp.bsh;
002    
003    import javax.swing.JFrame;
004    
005    import bsh.EvalError;
006    import bsh.Interpreter;
007    import bsh.util.JConsole;
008    
009    public class BshInterpreter {
010    
011            private Interpreter interpreter = null;
012    
013            public BshInterpreter() {
014                    interpreter = new Interpreter();
015                    try {
016                            interpreter.eval("import org.ujmp.*");
017                            interpreter.eval("import org.jdmp.*");
018                    } catch (EvalError e) {
019                            e.printStackTrace();
020                    }
021            }
022    
023            public void set(String name, Object object) {
024                    try {
025                            interpreter.set(name, object);
026                    } catch (EvalError e) {
027                            e.printStackTrace();
028                    }
029            }
030    
031            public Object eval(String command) {
032                    try {
033                            return interpreter.eval(command);
034                    } catch (EvalError e) {
035                            e.printStackTrace();
036                            return null;
037                    }
038            }
039    
040            public Object get(String name) {
041                    try {
042                            return interpreter.get(name);
043                    } catch (EvalError e) {
044                            e.printStackTrace();
045                            return null;
046                    }
047            }
048    
049            public static void main(String[] args) throws Exception {
050                    JFrame f = new JFrame();
051                    JConsole console = new JConsole();
052                    f.setContentPane(console);
053                    Interpreter interpreter = new Interpreter(console);
054                    interpreter.eval("import org.ujmp.core.*;");
055                    interpreter.eval("Matrix m=MatrixFactory.eye(new long[]{10,10});");
056                    new Thread(interpreter).start(); // start a thread to call the run()
057                    // method
058    
059                    f.setVisible(true);
060    
061            }
062    
063    }