从head java中copy一段代码,可是无法编译
eclipse提示button.addActionListener(this)的参数错误,要改成button.addActionListener((ActionListener) this);请问问题在哪?谢谢
下面是code
public void go(){
JFrame frame=new JFrame();
JPanel panel=new JPanel();
JButton button=new JButton("Just Click it");
button.addActionListener(this);
text=new JTextArea(10,20);
text.setLineWrap(true);
JScrollPane scroller=new JScrollPane(text);
scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
panel.add(scroller);
frame.getContentPane().add(BorderLayout.CENTER,panel);
frame.getContentPane().add(BorderLayout.SOUTH,button);
frame.setSize(350,300);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent ev){
text.append("button clicked \n");
}
eclipse提示button.addActionListener(this)的参数错误,要改成button.addActionListener((ActionListener) this);请问问题在哪?谢谢
下面是code
public void go(){
JFrame frame=new JFrame();
JPanel panel=new JPanel();
JButton button=new JButton("Just Click it");
button.addActionListener(this);
text=new JTextArea(10,20);
text.setLineWrap(true);
JScrollPane scroller=new JScrollPane(text);
scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
panel.add(scroller);
frame.getContentPane().add(BorderLayout.CENTER,panel);
frame.getContentPane().add(BorderLayout.SOUTH,button);
frame.setSize(350,300);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent ev){
text.append("button clicked \n");
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货