|
|
|
@ -2,6 +2,7 @@ package com.fr.design.jxbrowser;
|
|
|
|
|
|
|
|
|
|
import com.fr.design.DesignerEnvManager; |
|
|
|
|
import com.teamdev.jxbrowser.js.JsAccessible; |
|
|
|
|
import com.teamdev.jxbrowser.js.JsObject; |
|
|
|
|
|
|
|
|
|
import javax.swing.JButton; |
|
|
|
|
import javax.swing.JFrame; |
|
|
|
@ -10,6 +11,7 @@ import javax.swing.JPanel;
|
|
|
|
|
import javax.swing.WindowConstants; |
|
|
|
|
import java.awt.BorderLayout; |
|
|
|
|
import java.awt.FlowLayout; |
|
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
|
|
public class JxUIPaneTest { |
|
|
|
|
|
|
|
|
@ -30,16 +32,49 @@ public class JxUIPaneTest {
|
|
|
|
|
|
|
|
|
|
JPanel panel = new JPanel(new FlowLayout()); |
|
|
|
|
contentPane.add(panel, BorderLayout.SOUTH); |
|
|
|
|
|
|
|
|
|
testJxUIPaneUpdate(panel, pane); |
|
|
|
|
testExecuteJS1(panel, pane); |
|
|
|
|
testExecuteJS2(panel, pane); |
|
|
|
|
|
|
|
|
|
frame.setVisible(true); |
|
|
|
|
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static void testJxUIPaneUpdate(JPanel container, JxUIPane<Model> pane) { |
|
|
|
|
JButton button = new JButton("点击我可以看到Swing的弹框,输出填写的信息"); |
|
|
|
|
panel.add(button); |
|
|
|
|
button.addActionListener(e -> { |
|
|
|
|
Model returnValue = pane.update(); |
|
|
|
|
if (returnValue != null) { |
|
|
|
|
JOptionPane.showMessageDialog(frame, String.format("姓名为:%s,年龄为:%d", returnValue.getName(), returnValue.getAge())); |
|
|
|
|
JOptionPane.showMessageDialog(container.getRootPane(), String.format("姓名为:%s,年龄为:%d", returnValue.getName(), returnValue.getAge())); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
frame.setVisible(true); |
|
|
|
|
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); |
|
|
|
|
container.add(button); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static void testExecuteJS1(JPanel container, JxUIPane<Model> pane) { |
|
|
|
|
JButton button = new JButton("执行回显js对象内容"); |
|
|
|
|
button.addActionListener(e -> { |
|
|
|
|
pane.executeJavaScript("var pagesize={\"page\":1,\"size\":10};"); |
|
|
|
|
Optional<JsObject> value = pane.executeJS("pagesize"); |
|
|
|
|
value.ifPresent(v -> JOptionPane.showMessageDialog(container.getRootPane(), |
|
|
|
|
String.format("page为:%s,年龄为:%s", v.property("page").get(), v.property("size").get()))); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
container.add(button); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static void testExecuteJS2(JPanel container, JxUIPane<Model> pane) { |
|
|
|
|
JButton button = new JButton("执行回显数字内容"); |
|
|
|
|
button.addActionListener(e -> { |
|
|
|
|
pane.executeJavaScript("var tom = {\"age\":18};"); |
|
|
|
|
Optional<Double> value = pane.executeJS("tom.age"); |
|
|
|
|
JOptionPane.showMessageDialog(container.getRootPane(), |
|
|
|
|
String.format("var tom = {\"age\":18}; age:%s", value.get())); |
|
|
|
|
}); |
|
|
|
|
container.add(button); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@JsAccessible |
|
|
|
|