文档详情

JAVA计时器(秒表)程序代码.doc

发布:2019-06-15约2.91千字共8页下载文档
文本预览下载声明
. . Java计时器(秒表) 功能:能实现计时,暂停,清零,记录功能。如下图:程序运行状态: 源代码: import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Test { public static void main(String[] args){ new window(计时器); } } class window extends JFrame{ int ON=0,i=0,j=0,k=0,count=0,num=1,R=0; JButton button1,button2,button3,button4,button5; JTextField file1,file2,file3; JTextArea file; FlowLayout flow; String a,b,c; window(String name) { 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.setEditable(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(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); 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 actionPerformed(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 actionPerformed(ActionEvent e) { file.
显示全部
相似文档