import FESI.jslib.*; import java.awt.*; import java.awt.event.*; import java.io.*; class ScriptableEditor extends Frame implements ActionListener { TextArea text; Label status; JSGlobalObject global; ScriptableEditor() { super("ScriptableEditor"); setSize(500, 300); //ユーザーインタフェースの構築 addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); MenuBar menuBar = new MenuBar(); Menu menu = menuBar.add(new Menu("ファイル")); MenuItem item = menu.add(new MenuItem("スクリプト実行")); item.addActionListener(this); setMenuBar(menuBar); text = new TextArea(); add(text, BorderLayout.CENTER); status = new Label("Welcome to ScriptableEditor!"); add(status, BorderLayout.SOUTH); //インタプリタの生成 try { global = JSUtil.makeEvaluator(); Object obj = global.makeBeanWrapper(text); global.setMember("text", obj); } catch (JSException e) { System.err.println(e.getMessage()); System.exit(1); } } //メニューの処理 public void actionPerformed(ActionEvent ae) { FileDialog dialog = new FileDialog(this); dialog.show(); String scriptName = dialog.getDirectory(); if (scriptName == null) return; else scriptName += dialog.getFile(); Reader r = null; try { status.setText("実行中..."); r = new BufferedReader(new FileReader(scriptName)); Object result = global.eval(r, "スクリプト:" + scriptName); status.setText("完了: " + result); } catch (Exception e) { status.setText("エラー: " + e.getMessage()); } try { if (r != null) r.close(); } catch (IOException e) { } } public static void main(String[] args) { ScriptableEditor editor = new ScriptableEditor(); editor.setVisible(true); } }