【发布时间】:2010-12-22 23:38:52
【问题描述】:
我正在使用 JEditorPane 创建一个非常基本的 Web 浏览器,只是为了自学 Java 中的 Swing 和 GUI,但在实现类似 Firefox 的 Google 搜索栏时遇到了麻烦。
如果这是由于 JEditorPane 的限制或我缺乏理解,我不是,但如果我尝试将输入到“Google 搜索”栏中的字符串并使用 JEditorPane 的 setPage() 方法,它不会工作。
这是我的“Google 搜索”按钮的 ActionListener 代码:
public void actionPerformed(ActionEvent arg0)
{
try
{
content.setPage("http://www.google.com/search?q=" + searchBar.getText());
}
catch (IOException e)
{
JOptionPane.showMessageDialog(frame, "Error searching for: " + searchBar.getText());
}
}
即使我尝试只做 content.setPage("http://www.google.com/search?p=test");它不起作用,那么它与 setPage() 获取 URL 字符串的方式有关吗?因为它不喜欢“?”或“=”字符还是有其他方法可以一起完成?
感谢您的宝贵时间,
英菲尼迪菲兹
【问题讨论】:
标签: java user-interface swing jeditorpane