用java编写一个倒计时器代码 。import java.awt.BorderLayout;import java.awt.Container;import java.awt.Font;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;public class TimerDemo extends JFrame implements ActionListener {private static final long serialVersionUID = 201306211111L;private JTextField screen = new JTextField("0");private JButton start = new JButton("开始");private JButton reset = new JButton("重置");private JPanel panel = new JPanel();private boolean isRunning;private int time;private int timeBetween;public TimerDemo(int timeBetween) {super("计时器");this.timeBetween = timeBetween;try {init();} catch (Exception e) {e.printStackTrace();}}public TimerDemo() {super("计时器");this.timeBetween = 100;try {init();} catch (Exception e) {e.printStackTrace();}}private void init() {panel.setLayout(new GridLayout());panel.add(start);panel.add(reset);start.addActionListener(this);reset.addActionListener(this);screen.setFont(new Font("幼圆", Font.BOLD, 60));screen.setHorizontalAlignment(JTextField.CENTER);screen.setEditable(false);Container c = getContentPane();c.setLayout(new BorderLayout());c.add(panel, BorderLayout.SOUTH);c.add(screen, BorderLayout.CENTER);this.setSize(200, 150);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setResizable(false);this.setLocationRelativeTo(null);this.setVisible(true);}public static void main(String[] args) {new TimerDemo(1);// 设定 1ms/次// new TimerDemo();}@Overridepublic void actionPerformed(ActionEvent e) {if (e.getSource() == start) {if (start.getText().equals("开始")) {start.setText("暂停");isRunning = true;} else if (start.getText().equals("暂停")) {start.setText("开始");isRunning = false;}}if (e.getSource() == reset) {start.setText("开始");screen.setText("0");isRunning = false;time = 0;}new Thread(new TimeZone()).start();}class TimeZone implements Runnable {@Overridepublic void run() {while (isRunning) {time++;if (time = Integer.MAX_VALUE) {screen.setText("ERROR");JOptionPane.showMessageDialog(null, "ERROR");isRunning = false;}screen.setText(String.valueOf(time));try {Thread.sleep(timeBetween);} catch (Exception e) {e.printStackTrace();}}}}}
谁有用java的application编写的倒计时钟代码?package hello;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.util.*;
import java.awt.geom.*;
public class T extends Applet implements Runnable{
Thread tHour = null,tMinute = null,tSecond = null;//表示时针 , 分针和秒针的线程
int hour_a,hour_b,minute_a,minute_b,second_a,second_b;//表示时针 , 分针,秒针端点的整型变量
int hour = 0,minute = 0,second = 0;//获取当前时间的整型变量
//绘制时针,分针和秒针的Graphics对象
Graphics g_second = null,g_minute = null,g_hour =null;
//存放表盘刻度的数组 , 供指针走动时使用
doublepoint_x[] = new double[61],point_y[] = new double[61];
//存放表盘刻度的数组 , 供绘制表盘使用
double scaled_x[] = new double[61],scaled_y[] = new double[61];
//判断小程序是否重新开始的变量
int start_count = 0;
public void init(){
g_hour = this.getGraphics();
g_hour.setColor(Color.CYAN);
g_second = this.getGraphics();
g_second.setColor(Color.RED);
g_minute = this.getGraphics();
g_minute.setColor(Color.blue);
g_second.translate(200,200);//进行坐标系统变换,将新坐标系原点设在(200,200)处
g_minute.translate(200,200);
g_hour.translate(200,200);
point_x[0] = 0; point_y[0] = -120;//各个时针12点处的位置坐标(按新坐标系的坐标)
scaled_x[0] = 0;scaled_y[0] = -140;//12点处的刻度位置坐标(按新坐标系的坐标)
double jiaodu = 6*Math.PI/180;
推荐阅读
- 如何购买无人直播软件,无人直播怎么赚钱
- 直播间开场音乐是什么,直播开场曲
- 真人射击游戏场地广西汕头,真人射击游戏体验馆在哪里
- 传统媒体如何借力新媒体,传统媒体如何借力新媒体营销
- php无法链接数据库 php无法连接数据库
- oracle删掉用户表空间,oracle 删除用户表空间
- 联想cpu显卡怎么样,联想显卡性能排名
- 阿里云服务器端口如何打开,阿里云如何开放端口
- c语言接收键符函数 c语言接收字符