[英]Adding ActionListener to a JButton inside JEditorPane
在我的JEditorPane
我正在加載一個具有JButton
的html頁面:
<object classid="javax.swing.JButton" value="Button"></object>
如何為此JButton添加動作偵聽器?
嘗試這個。 首先創建一個Custom Button,如圖所示。
import java.awt.event.*;
import javax.swing.JButton;
public class htmlButton extends JButton
{
public htmlButton()
{
addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent a)
{
System.out.println("HAI");
}
});
}
}
HTML部分:
<html>
<body>
<object classid="htmlButton" value="Button"></object> HAI
</body>
</html>
EditorPane Part
JEditorPane pan=new JEditorPane();
pan.setPage(new java.io.File("a.html").toURL());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.