记录按钮按下次数的java代码中在jb.addActionListener这一行有一个错误,不知道怎么错了
packagechapter03.sample7_4;importjava.awt.event.ActionEvent;importjava.awt.event.Acti...
package chapter03.sample7_4;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Sample7_4 extends JFrame{
private JPanel jp=new JPanel();
private JButton jb=new JButton("按钮");
private JLabel jl=new JLabel("按钮按下了0次");
private int count=0;
public Sample7_4(){
jp.add(jb);
jp.add(jl);
this.add(jp);
jb.addActionListener(new ActionLisrener(){
public void actionPerformed(ActionEvent e){
Sample7_4.this.jl.setText("按钮按下了"+(++count)+"次");
}
});
this.setBounds(100,100,400,130);
this.setVisible(true);
}
public static void main(String[] args){
new Sample7_4();
}
} 展开
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Sample7_4 extends JFrame{
private JPanel jp=new JPanel();
private JButton jb=new JButton("按钮");
private JLabel jl=new JLabel("按钮按下了0次");
private int count=0;
public Sample7_4(){
jp.add(jb);
jp.add(jl);
this.add(jp);
jb.addActionListener(new ActionLisrener(){
public void actionPerformed(ActionEvent e){
Sample7_4.this.jl.setText("按钮按下了"+(++count)+"次");
}
});
this.setBounds(100,100,400,130);
this.setVisible(true);
}
public static void main(String[] args){
new Sample7_4();
}
} 展开
2个回答
展开全部
package sample;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Sample7_4 extends JFrame
{
public static void main(final String[] args)
{
new Sample7_4();
}
private JPanel jp = new JPanel();
private JButton jb = new JButton("按钮");
private JLabel jl = new JLabel("按钮按下了0次");
private int count = 0;
public Sample7_4()
{
jp.add(jb);
jp.add(jl);
this.add(jp);
jb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e)
{
jl.setText("按钮按下了" + ++count + "次");
}
});
this.setBounds(100, 100, 400, 130);
setVisible(true);
}
}
拼写错误
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询