编写一个程序,其功能为:在窗口上放一个按钮,当不断单击按钮时显示它被单击的次数。
importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;publicclassClicksNumberex...
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ClicksNumber extends JFrame{
private JButton button=new JButton("请点击");
Container container=this.getContentPane();
public ClicksNumber(){
this.setTitle("欢迎使用");
container.setLayout(new FlowLayout());
button.addActionListener(new ButtonEventHandle());
container.add(button);
this.show();
this.setSize(300,400);
}
class ButtonEventHandle implements ActionListener{
public void actionPerform(ActionEvent e){
int count=0; count++;count=count++;
System.out.println("按钮被点击了"+count+"次");
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new ClicksNumber();
}
}帮我看下这个错误在哪吧 展开
import java.awt.*;
import java.awt.event.*;
public class ClicksNumber extends JFrame{
private JButton button=new JButton("请点击");
Container container=this.getContentPane();
public ClicksNumber(){
this.setTitle("欢迎使用");
container.setLayout(new FlowLayout());
button.addActionListener(new ButtonEventHandle());
container.add(button);
this.show();
this.setSize(300,400);
}
class ButtonEventHandle implements ActionListener{
public void actionPerform(ActionEvent e){
int count=0; count++;count=count++;
System.out.println("按钮被点击了"+count+"次");
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new ClicksNumber();
}
}帮我看下这个错误在哪吧 展开
1个回答
展开全部
事件写的有问题,我一修改,你自己看一下吧
package TEST;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ClicksNumber extends JFrame{
private JButton button=new JButton("请点击");
Container container=this.getContentPane();
private static int i = 0;
public ClicksNumber(){
this.setTitle("欢迎使用");
container.setLayout(new FlowLayout());
button.addActionListener(new ButtonEventHandle());
container.add(button);
this.show();
this.setSize(300,400);
}
class ButtonEventHandle implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
i++;
button.setText("you have clicked this button "+i+"times");
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new ClicksNumber();
}
}
package TEST;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ClicksNumber extends JFrame{
private JButton button=new JButton("请点击");
Container container=this.getContentPane();
private static int i = 0;
public ClicksNumber(){
this.setTitle("欢迎使用");
container.setLayout(new FlowLayout());
button.addActionListener(new ButtonEventHandle());
container.add(button);
this.show();
this.setSize(300,400);
}
class ButtonEventHandle implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
i++;
button.setText("you have clicked this button "+i+"times");
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new ClicksNumber();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询