java测试鼠标点击速度的程序
importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjavax.swing.Timer;i...
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.Timer;
import java.util.*;
public class Button
{
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
ActionListener listener = new TimePrinter();
Timer t = new Timer(5000, listener);
ButtonFrame frame = new ButtonFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setResizable(false);
}
});
}
}
class ButtonFrame extends JFrame
{
int con = 0;
public int getcon()
{
return con;
}
public ButtonFrame()
{
ActionListener listener = new TimePrinter();
final Timer t = new Timer(5000, listener);
getContentPane().setLayout(null);
setTitle("Button");
setSize(DEFAULT_WIDTH, DEFAULT_WIDTH);
JButton PButton = new JButton("Press me!");
txt = new JTextField();
txt.setBounds(125, 150, 50, 20);
getContentPane().add(txt);
getContentPane().add(PButton);
JButton QButton = new JButton("Clear");
QButton.setBounds(110,180,80,50);
getContentPane().add(QButton);
PButton.setBounds(70,75,160,40);
PButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
t.start();
con++;
txt.setText(String.valueOf(con));
}
});
QButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
con = 0;
txt.setText(String.valueOf(con));
}
});
}
private JPanel buttonPanel;
private JTextField txt;
public static final int DEFAULT_WIDTH = 300;
public static final int DEFAULT_HEIGHT = 200;
}
class TimePrinter implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
System.out.println("APM is" + con*12);
}
}
最后的con变量访问有问题。另外怎么弹出窗口显示con*12,而非print。 展开
import java.awt.event.*;
import javax.swing.*;
import javax.swing.Timer;
import java.util.*;
public class Button
{
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
ActionListener listener = new TimePrinter();
Timer t = new Timer(5000, listener);
ButtonFrame frame = new ButtonFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setResizable(false);
}
});
}
}
class ButtonFrame extends JFrame
{
int con = 0;
public int getcon()
{
return con;
}
public ButtonFrame()
{
ActionListener listener = new TimePrinter();
final Timer t = new Timer(5000, listener);
getContentPane().setLayout(null);
setTitle("Button");
setSize(DEFAULT_WIDTH, DEFAULT_WIDTH);
JButton PButton = new JButton("Press me!");
txt = new JTextField();
txt.setBounds(125, 150, 50, 20);
getContentPane().add(txt);
getContentPane().add(PButton);
JButton QButton = new JButton("Clear");
QButton.setBounds(110,180,80,50);
getContentPane().add(QButton);
PButton.setBounds(70,75,160,40);
PButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
t.start();
con++;
txt.setText(String.valueOf(con));
}
});
QButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
con = 0;
txt.setText(String.valueOf(con));
}
});
}
private JPanel buttonPanel;
private JTextField txt;
public static final int DEFAULT_WIDTH = 300;
public static final int DEFAULT_HEIGHT = 200;
}
class TimePrinter implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
System.out.println("APM is" + con*12);
}
}
最后的con变量访问有问题。另外怎么弹出窗口显示con*12,而非print。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询