在扩展JEditorPane
的子类中设置新文本时遇到问题。Index
JFrame
package gui;
...
public class Index extends JFrame {
JEditorPane editorPaneMR = new JEditorPane();
public static void main(String[] args) {
...
}
public Index() {
JButton SearchButton = new JButton("OK");
SearchButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
parser GooBlog = new parser(url);
try {
GooBlog.hello(); // Go to subclass parser
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
这就是称为解析器的子类的代码
package gui;
public class parser extends Index{
String url;
public parser (String urlInput){
this.url = urlInput;
}
public void hello () throws IOException{
editorPaneMR.setText("Hello World");
}
}
问题是当我按下确定按钮时,它没有在 JEditorPane 中显示文本“Hello world”!它没有向我显示任何错误,只是没有发生任何事情。