JAVA怎么实现在规定时间记录点击按钮的次数
publicclassMyJbuttonTest{publicstaticvoidmain(String[]args){MyFramemf=newMyFrame();wh...
public class MyJbuttonTest {
public static void main(String[] args) {
MyFrame mf=new MyFrame();
while(true){
if(!(mf.s.equals("第0次按按钮"))){
for(int i=0;i<=9;i++){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
mf.time++;
mf.jl1.setText(String.valueOf(mf.time));
}
return;
}else{
continue;
}
}
}
}
class MyFrame extends JFrame{
JPanel jp=new JPanel();
static JLabel jl=new JLabel("第0次按按钮");
int count=0;
ImageIcon ic=new ImageIcon(
"C:\\Users\\Administrator\\Desktop\\icon.jpg");
JButton jb=new JButton(ic);
static int time=0;
JLabel jl1=new JLabel("0");
static String s;
public MyFrame(){
jl.setForeground(Color.blue);
jp.add(jb);
jp.add(jl);
jp.add(jl1);
jl1.setLocation(10, 10);
this.add(jp);
this.setTitle("MyJButton使用");
Toolkit tk=Toolkit.getDefaultToolkit();
Dimension d=tk.getScreenSize();
this.setSize(d);
this.setVisible(true);
this.addWindowListener(new WindowAdapter(){
public void windwClosing(WindowEvent e){
System.exit(0);
}
});
jb.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
jl.setText("第"+ (++count)+"次点击");
s=jl.getText();
}
});
}
} 展开
public static void main(String[] args) {
MyFrame mf=new MyFrame();
while(true){
if(!(mf.s.equals("第0次按按钮"))){
for(int i=0;i<=9;i++){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
mf.time++;
mf.jl1.setText(String.valueOf(mf.time));
}
return;
}else{
continue;
}
}
}
}
class MyFrame extends JFrame{
JPanel jp=new JPanel();
static JLabel jl=new JLabel("第0次按按钮");
int count=0;
ImageIcon ic=new ImageIcon(
"C:\\Users\\Administrator\\Desktop\\icon.jpg");
JButton jb=new JButton(ic);
static int time=0;
JLabel jl1=new JLabel("0");
static String s;
public MyFrame(){
jl.setForeground(Color.blue);
jp.add(jb);
jp.add(jl);
jp.add(jl1);
jl1.setLocation(10, 10);
this.add(jp);
this.setTitle("MyJButton使用");
Toolkit tk=Toolkit.getDefaultToolkit();
Dimension d=tk.getScreenSize();
this.setSize(d);
this.setVisible(true);
this.addWindowListener(new WindowAdapter(){
public void windwClosing(WindowEvent e){
System.exit(0);
}
});
jb.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
jl.setText("第"+ (++count)+"次点击");
s=jl.getText();
}
});
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询