指望有多少次的JButton是pressed? [英] Count how many times a JButton is pressed?

查看:173
本文介绍了指望有多少次的JButton是pressed?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在所执行的操作在Java GUI code,我怎么算一个按钮有多少次是pressed,并做一些按钮的每个preSS?

In the action performed code in a JAVA GUI, how would I count how many times a button is pressed, and do something different for each press of the button?

  private class Listener implements ActionListener
  {
     public void actionPerformed (ActionEvent e)
     {

       HOW WOULD I COUNT HOW MANY TIMES THIS BUTTON HAS BEEN PRESSED?

     }

谢谢!

推荐答案

创建一个类变量,然后递增该方法的变量。

Create a class variable and then increment the variable in the method.

private class Listener implements ActionListener   
{      
    private int clicked;

    public void actionPerformed (ActionEvent e)
    {
         clicked++
    }
}

您可以创建访问变量的方法。

You can then create a method to access the variable.

这篇关于指望有多少次的JButton是pressed?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆