我试图找到一些代表一组 HTML 对象显示的 java 代码(即该代码将进入绘制函数)。这是为了进入一个自制的 HTML 和 javascript IDE(由于复杂的原因,我无法使用现成的版本)
我无法使用图像来表示 HTML 对象,因为属性(边框颜色等)都需要更改。
简而言之,我需要可以在 HTML 组件的 Paint 方法中使用的代码。
有人知道我可以在哪里得到这个吗?或者知道如何去做。我只是尝试手写代码来表示选择标签,这非常困难。
编辑: 事实证明(如下所述)我正在寻找的是一个 HTML 渲染器。但是,我的代码是 javascript,它被浏览器解释为 HTML。以下代码是由 IDE 生成的,我有一种访问所需属性(borderColor 等)的方法,我需要的是一种将这些属性渲染到 JPanel 上的方法。即如何在代表下面 DIV 的 JPanel 上绘制一个红色框(简单的示例,我可以做到这一点,但对于一个大子集(最好是所有)css 属性需要相同):
function componentName(constructor, properties){
this.style = {}
this.style.left = 0; //@property TYPE_TEXT left
this.style.top = 0; //@property TYPE_TEXT top
this.style.width = 100; //@property TYPE_TEXT width
this.style.height = 50; //@property TYPE_TEXT height
this.body0 = document.body
this.body0.onmousedown = this.this.body0_onmousedown
this.body0.style.borderStyle = ""
this.body0.style.borderWidth = "0px"
this.body0.style.overflow = "auto"
this.body0.style.top = "0px"
this.body0.style.left = "0px"
this.body0.style.position = "fixed"
this.body0.name = ""
this.body0.style.backgroundColor = "#ffffff"
this.body0.onmousedown = this.body0_onmousedown
this.body0.style.width = "296px"
this.body0.style.height = "193px"
this.DIV0 = document.createElement("DIV")
this.DIV0.style.height = "216px"
this.DIV0.style.width = "181px"
this.DIV0.onmousedown = this.DIV0_onmousedown
this.DIV0.style.top = "40px"
this.DIV0.style.backgroundColor = "#ff0000"
...etc
}
最佳答案
您可以尝试Java DOM 。例如,有一个Element
界面。具体实现有多种,包括IIOMetadataNode
关于HTML 对象的 Java 表示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9935601/