equal
deleted
inserted
replaced
1 #// Usage: jjs -fx browser.js |
1 #// Usage: jjs -fx browser_dom.js |
2 |
2 |
3 /* |
3 /* |
4 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
4 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
5 * |
5 * |
6 * Redistribution and use in source and binary forms, with or without |
6 * Redistribution and use in source and binary forms, with or without |
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
32 */ |
32 */ |
33 |
33 |
34 if (!$OPTIONS._fx) { |
34 if (!$OPTIONS._fx) { |
35 print("Usage: jjs -fx browser.js"); |
35 print("Usage: jjs -fx browser_dom.js"); |
36 exit(1); |
36 exit(1); |
37 } |
37 } |
38 |
38 |
39 // JavaFX classes used |
39 // JavaFX classes used |
40 var ChangeListener = Java.type("javafx.beans.value.ChangeListener"); |
40 var ChangeListener = Java.type("javafx.beans.value.ChangeListener"); |
72 var document = wv.engine.document; |
72 var document = wv.engine.document; |
73 // DOM manipulation |
73 // DOM manipulation |
74 var btn = document.createElement("button"); |
74 var btn = document.createElement("button"); |
75 var n = 0; |
75 var n = 0; |
76 // attach a button handler - nashorn function! |
76 // attach a button handler - nashorn function! |
77 btn.onclick = new EventListener(function() { |
77 btn.onclick = function() { |
78 n++; print("You clicked " + n + " time(s)"); |
78 n++; print("You clicked " + n + " time(s)"); |
79 print("you clicked OK " + wv.engine.executeScript("okCount")); |
79 print("you clicked OK " + wv.engine.executeScript("okCount")); |
80 }); |
80 }; |
81 // attach text to button |
81 // attach text to button |
82 var t = document.createTextNode("Click Me!"); |
82 var t = document.createTextNode("Click Me!"); |
83 btn.appendChild(t); |
83 btn.appendChild(t); |
84 // attach button to the document |
84 // attach button to the document |
85 document.body.appendChild(btn); |
85 document.body.appendChild(btn); |