如何让我的textarea接受像编译器这样的脚本引擎中的输入?

时间:2016-02-28 12:40:33

标签: javascript java

ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");

    try {
        engine.eval("load(\"nashorn:mozilla_compat.js\");");
        engine.eval( ""
                + "var Gui = new JavaImporter(java.awt, javax.swing,java.awt.event,javax.swing.event);"
                + "with (Gui) {\n" 
                + "var jframe = new JFrame(\"Console\");\n"
                + "var textarea = new JTextArea(10,30);\n"
                + "var jScrollPane = new JScrollPane(textarea);\n"
                + "jframe.add(jScrollPane);"
                + "jframe.setSize(500,300);"

                +"var Name;"
                + "textarea.append(\"HELLO \");"
                + "jframe.setVisible(true);"

                + "if(keyCode==KeyEvent.VK_ENTER){"
                + "Name= ;"
                + "textarea.append(\"\"+ Name );"

                + "}"
                + "setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);" 
                + "jframe.setVisible(true);"
                + "}");


    } catch (ScriptException ex) {
        Logger.getLogger(Compiler.class.getName()).log(Level.SEVERE, null, ex);
    }

0 个答案:

没有答案