java 秒表_JAVA计时器秒表程序代码

《JAVA计时器秒表程序代码》由会员分享,可在线阅读,更多相关《JAVA计时器秒表程序代码(7页珍藏版)》请在人人文库网上搜索。

1、Java计时器(秒表)功能:能实现计时,暂停,清零,记录功能。如下图:程序运行状态: 源代码:import javax.swing.*;import java.awt.*;importpublic class Test public static void main(Stringargs )new window(计时器”);class window extends JFrameint ON=0, i =0, j =0, k=0, count =0, num=1, R=0;JButton button1 , button2 , button3 , button4 , button5JTextFi。

2、eld file1 , file2 , file3 ;JTextArea file ;FlowLayout flow ;String a, b, c;win dow(Stri ng n ame)file1 =new JTextField(2);file2 =new JTextField(2);file3 =new JTextField(2);file1 .setEditable( false ); file2 .setEditable( false ); file3 .setEditable( false ); file =new JTextArea(10,8); file .setEdita。

3、ble( false ); button1 =new JButton( 开始 ); button2 =new JButton( 暂停 ); button3 =new JButton( 清零 ); button4 =new JButton( 记录 ); button5 =new JButton( 清空记录 ); flow =new FlowLayout();flow .setAlignment(FlowLayout. LEFT); flow .setHgap(20);flow .setVgap(10); setTitle( name); setSize(210,400); setLayout( 。

4、flow );add( file1 );add( new JLabel( : );add( file2 );add( new JLabel( : );add( file3 ); add( button1 ); add( button2 ); add( button3 ); add( button4 ); add( button5 ); add( file );setVisible( true );setDefaultCloseOperation( EXIT_ON_CLOSE);file1 .setText( 0 );file2 .setText( 0 );file3 .setText( 0 )。

5、;validate();button1 .addActionListener( new ActionListener() public void actionPerformed(ActionEvent e) ON=1; / 开始,暂停控制开关); / 开始按钮button2 .addActionListener( new ActionListener() public void actionPerformed(ActionEvent e) ON=0;); / 暂停按钮button3 .addActionListener( new ActionListener() public void act。

6、ionPerformed(ActionEvent e) R=1; / 清零控制开关); / 清零按钮button4 .addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) count =1; / 记录控制开关a=String.valueOf (i );b=String.valueOf (j );c =String.valueOf (k);); / 记录按钮button5 .addActionListener(new ActionListener() public void action。

7、Performed(ActionEvent e) file .setText( );num=1;); / 清除记录按钮while (true )validate();if ( ON=1) / 开始或暂停判断file1.setText(String.valueOf ( i );file2.setText(String.valueOf(j );file3.setText(String.valueOf( k);if ( k=99)k=-1;j +;if ( j =60)k=0;j =0;i +;if ( i =24)i =0;j =0;k=0;try Thread. sleep (10);catch。

8、 (Exception e) k+;if ( count =1)/ 记录判断file.append(String.valueOf ( num);file.append(. );file.append(a);file.append(: );file.append(b);file.append(: );file.append(c);file.append(n );num+;count =0;if (R=1) 清零判断i =j =k=0;valueOf (i );valueOf (j );valueOf (k);filel.setText(Stri ng.file2.setText(Stri ng.file3.setText(Stri ng.R=0。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值