设计一个鼠标点击速度比赛游戏
代码如下:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class shubiaodj extends JFrame implements ActionListener {
JTextField tf;
int a;
shubiaodj(){
JFrame jf = new JFrame("鼠标点击速度大比拼");//软件名称
jf.setVisible(true);
jf.setSize(250, 200);//设置窗口体积
jf.setLocationRelativeTo(null);
JLabel jl=new JLabel("点击次数");//标签
tf= new JTextField(10);// 文本框
JButton but= new JButton("请连续点击");//Button按钮
but.addActionListener(this);
jf.add(jl);
jf.add(tf);
jf.add(but);
jf.setLayout(new FlowLayout());
}
public void actionPerformed(ActionEvent e){
String s = e.getActionCommand() ;
if(s.equals("请连续点击"))
tf.setText(""+a++);
}
public static void main(String[] args) {
new shubiaodj() ;
}
}
本文介绍了一款简单的Java Swing应用程序,用于测试用户的鼠标点击速度。通过连续点击按钮,程序会记录并显示点击次数,以此来衡量参与者的反应速度。
2万+

被折叠的 条评论
为什么被折叠?



