代码

package src;


 import java.awt.*;
 import java.awt.event.*;
 import javax.swing.*;


 public class sbdj  {
public static void main(String[] args) {
new MyFrame(" 鼠标点击大比拼");
}


 }
 @SuppressWarnings("serial")
 class MyFrame extends JFrame implements ActionListener{
JLabel explainLabel=new JLabel (" 点击次数");
JTextField text=new JTextField("          ");
int count=0;
JButton button=new JButton("请连续点击");
public MyFrame(String title) {
setTitle(title);
setLayout(new FlowLayout());
add(explainLabel);
add(text);
button.addActionListener(this);
add(button);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100,100,200,200);
pack();
}
@Override
public void actionPerformed(ActionEvent e) {
count++;
text.setText(" "+count+" ");
}
 }
运行结果
鼠标点击游戏作业

相关文章: