秒表的个个位数的计算:

package Seconds;

public class Watch_time extends Thread{

int ms,ms_1,ms_2;

int s,s_1;

int m,m_1;

Watch w;

public void set(Watch w) {

this.w=w;

}

public void setNum() {

ms=ms_1= s=s_1=m=m_1=0;

}

public void run() {

while(true) {

try {

Thread.sleep(9);

ms_1++;

if(ms_1==10) {

ms_1=0;

ms++;

}

if(ms==10) {

ms=0;

s_1++;

}

if(s_1==10) {

s_1=0;

s++;

}

if(s==6) {

s=0;

m_1++;

}

if(m_1==10) {

m_1=0;

m++;

}

w.textArea.setText(m+""+m_1+":"+s+""+s_1+"."+ms+""+ms_1);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

}

Frame类:

可视化界面

package Seconds;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.border.EmptyBorder;

import javax.swing.JTextArea;

import javax.swing.GroupLayout;

import javax.swing.GroupLayout.Alignment;

import javax.swing.JButton;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

import javax.swing.JScrollPane;

import java.awt.SystemColor;

import java.awt.Font;

import javax.swing.UIManager;

import javax.swing.LayoutStyle.ComponentPlacement;

import org.eclipse.wb.swing.FocusTraversalOnArray;

import java.awt.Component;

import java.awt.Color;

public class Watch extends JFrame {

/**

*

*/

private static final long serialVersionUID = 1L;

private JPanel contentPane;

JTextArea textArea = new JTextArea();

int a=1;

int i=0;

public Watch(Watch_time w) {

setTitle("\u79D2\u8868\u8BA1\u65F6\u5668 --\u00A9Dong");

textArea.setText("00:00.00");

setVisible(true);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setBounds(100, 100, 450, 300);

contentPane = new JPanel();

JScrollPane scrollPane = new JScrollPane();

scrollPane.setEnabled(false);

contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

setContentPane(contentPane);

JTextArea textArea_1 = new JTextArea();

textArea_1.setFont(new Font("Monospaced", Font.BOLD | Font.ITALIC, 13));

textArea_1.setEditable(false);

textArea_1.setBackground(UIManager.getColor("Button.background"));

JTextArea textArea_2 = new JTextArea();

textArea_2.setFont(UIManager.getFont("Viewport.font"));

textArea_2.setEditable(false);

textArea_2.setText(" \u51C6\u5907\u8BA1\u65F6");

textArea_2.setBackground(SystemColor.control);

JButton btnNewButton=new CircleButton("开始",Color.GREEN);

btnNewButton.setBackground(Color.CYAN);

JButton btnNewButton_1=new CircleButton("\u8BB0\u5F55",Color.GREEN);

JButton btnNewButton_2=new CircleButton("\u91CD\u7F6E",Color.GREEN);

btnNewButton.addActionListener(new ActionListener() {

@SuppressWarnings("deprecation")

public void actionPerformed(ActionEvent e) {

if(btnNewButton.getText().equals("开始"))

{

if(a==1) {

w.start();

textArea_2.setText(" 正在计时");

btnNewButton_1.setEnabled(true);

btnNewButton_2.setEnabled(false);

btnNewButton.setText("暂停");

a=2;

}

else {

textArea_2.setText(" 正在计时");

btnNewButton_1.setEnabled(true);

btnNewButton_2.setEnabled(false);

w.resume();

btnNewButton.setText("暂停");

}

}

else {

textArea_2.setText(" 暂 "+" 停");

btnNewButton_1.setEnabled(false);

btnNewButton_2.setEnabled(true);

w.suspend();

btnNewButton.setText("开始");

}

}

});

btnNewButton_1.setEnabled(false);

btnNewButton_1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

textArea_1.append("第"+(++i)+"次计数:"+textArea.getText()+'\n');

}

});

btnNewButton_2.setEnabled(false);

btnNewButton_2.addActionListener(new ActionListener() {

@SuppressWarnings("deprecation")

public void actionPerformed(ActionEvent e) {

textArea_1.setText("");

i=0;

btnNewButton_2.setEnabled(false);

textArea.setText("00:00.00");

textArea_2.setText(" 准备计时");

w.suspend();

w.setNum();

}

});

GroupLayout gl_contentPane = new GroupLayout(contentPane);

gl_contentPane.setHorizontalGroup(

gl_contentPane.createParallelGroup(Alignment.TRAILING)

.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 425, Short.MAX_VALUE)

.addGroup(gl_contentPane.createSequentialGroup()

.addGap(48)

.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 77, GroupLayout.PREFERRED_SIZE)

.addGap(38)

.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)

.addGroup(gl_contentPane.createSequentialGroup()

.addComponent(btnNewButton_2, GroupLayout.PREFERRED_SIZE, 72, GroupLayout.PREFERRED_SIZE)

.addGap(44)

.addComponent(btnNewButton_1, GroupLayout.PREFERRED_SIZE, 72, GroupLayout.PREFERRED_SIZE)

.addContainerGap())

.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()

.addComponent(textArea, GroupLayout.PREFERRED_SIZE, 128, GroupLayout.PREFERRED_SIZE)

.addContainerGap(134, Short.MAX_VALUE))

.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()

.addComponent(textArea_2, GroupLayout.DEFAULT_SIZE, 84, Short.MAX_VALUE)

.addGap(178))))

);

gl_contentPane.setVerticalGroup(

gl_contentPane.createParallelGroup(Alignment.TRAILING)

.addGroup(gl_contentPane.createSequentialGroup()

.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 64, Short.MAX_VALUE)

.addGap(33)

.addComponent(textArea, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)

.addPreferredGap(ComponentPlacement.RELATED)

.addComponent(textArea_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)

.addGap(15)

.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)

.addComponent(btnNewButton_2, GroupLayout.PREFERRED_SIZE, 68, GroupLayout.PREFERRED_SIZE)

.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 66, GroupLayout.PREFERRED_SIZE)

.addComponent(btnNewButton_1, GroupLayout.PREFERRED_SIZE, 66, GroupLayout.PREFERRED_SIZE))

.addGap(44))

);

textArea.setEditable(false);

textArea.setFont(new Font("Monospaced", Font.BOLD | Font.ITALIC, 16));

textArea.setBackground(SystemColor.control);

scrollPane.setViewportView(textArea_1);

contentPane.setLayout(gl_contentPane);

contentPane.setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{scrollPane, btnNewButton, textArea_1, btnNewButton_1, textArea, btnNewButton_2, textArea_2}));

}

}

简单的秒表计时器java报告_简单的Java秒表计时器(线程)相关推荐

  1. JAVA拳皇_拳皇(Java简单的小程序)代码实例|chu

    刚开始学习Java,看完老九君的视频根据他的内容敲的代码,感觉还挺有成就感的,毕竟刚学习Java. package helloasd;import java.util.*; public class ...

  2. 蚁群算法java实现_简单蚁群算法 + JAVA实现蚁群算法

    一 引言 蚁群算法(ant colony optimization,ACO),又称蚂蚁算法,是一种用来在图中寻找优化路径的机率型技术.它由Marco Dorigo于1992年在他的博士论文中引入,其灵 ...

  3. 小学数学闯关游戏 java代码_简单的java程序 小学数学闯关游戏 多谢高分

    展开全部 有4个类 MainFrame,Question,QuestionPanel,ResultPanel import java.awt.BorderLayout; import java.awt ...

  4. java多线程贪吃蛇实验报告_贪吃蛇java实验报告.docx

    贪吃蛇java实验报告 贪吃蛇java实验报告 篇一:JAVA贪吃蛇课程设计报告 <Java应用开发> 课程设计报告 题 目:指导老师:姓 名:专 业:班 级:日 期: JAVA小游戏 - ...

  5. groovy 使用java类_深入学习java中的Groovy 和 Scala 类

    前言 Java 传承的是平台,而不是语言.有超过 200 种语言可以在 JVM 上运行,它们之中不可避免地会有一种语言最终将取代 Java 语言,成为编写 JVM 程序的最佳方式.本系列将探讨三种下一 ...

  6. java 枚举_深入理解Java枚举

    所有知识体系文章,[GitHub](https://github.com/Ziphtracks/JavaLearningmanual)已收录,欢迎Star!再次感谢,愿你早日进入大厂! https:/ ...

  7. java安装_在线学习Java编程的最佳方法

    java安装 1.简介 Java是使用最广泛的编程语言之一. 根据Github的最新报告,Java被列为仅次于JavaScript的第二大最常用的编程语言. 掌握Java的人有很多话题. 好消息是,您 ...

  8. 什么是java序列化_什么是Java序列化?为什么序列化?序列化有哪些方式?

    先普及一下,计算机中无法识别一个基本单元[字节]来表示,必须经过"翻译"才能让计算机理解人类的语言,这个翻译过程就是[编码],通常所说的字符转换为字节. ?有I/O的地方机就会涉及 ...

  9. java学习_都说Java难学,不知道具体的学习内容?全套Java学习路线送上

    首先,我个人比较推崇的学习方法是:先学java前段,也就是HTML,css,js,因为学习java以后肯定是往java ee方向发展的,学习完前端,在学习后端很多东西比计较容易理解! 其中J2SE是关 ...

最新文章

  1. 用无序列表做的网站公告牌(Billboard)
  2. 图(Graph)的javascript实现
  3. 过拟合(原因、解决方案、原理)
  4. AAAI 2019 四个杰出论文奖论文揭晓
  5. 计算机网络拓扑分层,计算机网络和工程实践教程讲座主讲内容网络拓扑和分层体系结构.ppt...
  6. 台式计算机拆机步骤ppt,三相异步电动机拆装的方法和步骤.PPT
  7. html弹窗代码大全定时弹窗,js点击弹窗弹出表单框代码
  8. spss多元线性回归散点图_如何通过残差散点图检验SPSS线性回归是否存在异方差等问题?...
  9. 游戏对战平台编写流程
  10. Apache探索:Windows下搭建PHP运行环境(详细图文教程)
  11. Excel 表格删除重复数据
  12. softlayer iso_使用SoftLayer创建安全的WordPress博客
  13. 带孔缝箱体屏蔽效能仿真分析
  14. Linux下搭建Cortex-M嵌入式开发环境
  15. 双目相机IMX219-83 +jetson nano 使用教程
  16. FCF中文指南-第七章--FusionCharts Free和XML
  17. 性别年龄论文阅读(2)——CACD2000
  18. [Android]第一个Android软件/demo
  19. MOS管之开关控制与信号控制
  20. 周末用了下Google Allo:有些弱,百度度秘比它强

热门文章

  1. Eclipse+STS 恢复默认主题
  2. 用adb命令快速查看某应用appPackage及appActivity的方法
  3. 神经元与神经网络结构
  4. 解析mysql不重复字段值求和
  5. Linux内核版本介绍与查询
  6. linux df命令none,linux磁盘命令中df命令的作用
  7. 字符串函数讲解(C语言笔记,建议收藏!!!)
  8. WampServer2.0i.exe可正常安装ECShop_V2.7.2 utf8
  9. 主动式和被动式电容笔哪个好用?第三方电容笔推荐
  10. BASIC 之父出生 | 历史上的今天