发布网友 发布时间:2022-04-22 00:36
共2个回答
热心网友 时间:2023-09-24 02:28
下载一个JAVA软件,然后安装。打开后输入
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class Clock extends JFrame
{
private Dialog dialog;
public static void main(String[] args)
{
Clock f = new Clock();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
class MyDialog extends Dialog implements WindowListener,ActionListener
{
JLabel label;
JPanel panel1,panel2;
JButton button;
public MyDialog(Frame owner, String title, boolean modal) {
super(owner, title, modal);
// TODO Auto-generated constructor stub
label=new JLabel("时间到!");
button=new JButton("确定");
panel1=new JPanel();
panel2=new JPanel();
panel1.setLayout(new BorderLayout());
panel1.add("Center",label);
panel2.add("Center",button);
this.add("Center",panel1);
this.add("South",panel2);
this.setSize(200,200);
this.setResizable(false);
this.addWindowListener(this);
button.addActionListener(this);
}
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub
}
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
this.setVisible(false);
}
public void windowClosed(WindowEvent e) {
// TODO Auto-generated method stub
}
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub
}
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub
}
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub
}
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
this.setVisible(false);
}
}
Clock()
{
setTitle("倒计时");
setSize(320, 120);
dialog=new MyDialog(this,"提示:",true);
ClockPanel p = new ClockPanel();
add(p);
}
class ClockPanel extends JPanel
{
private JButton b;
private boolean onetime = true;;
private JLabel lfen, lmiao, l;
private JTextField tf, tm;
ClockPanel() {
b = new JButton("开始倒计时");
lfen = new JLabel("分");
lmiao = new JLabel("秒");
l = new JLabel("00:00");
tf = new JTextField(3);
tm = new JTextField(3);
l.setFont(new Font("宋体", Font.BOLD, 30));
l.setForeground(Color.RED);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (onetime) {
if (tf.getText().trim().equals("")) {
tf.setText("00");
}
if (tm.getText().trim().equals("")) {
tm.setText("00");
}
new ChangeLabel(tf.getText().trim() + ":"
+ tm.getText().trim()).start();
}
}
});
add(tf);
add(lfen);
add(tm);
add(lmiao);
add(b);
add(l);
}
class ChangeLabel extends Thread // 运行秒针线程
{
private int minitues;
private String Sminitues;
private int sound;
private String Ssound;
private String LabelTime;
public ChangeLabel(String time) {
// TODO Auto-generated constructor stub
onetime = false;
this.minitues = Integer.parseInt(time.substring(0, time
.indexOf(':')));
this.sound = Integer
.parseInt(time.substring(time.indexOf(':') + 1));
}
private long time1;
private long time2;
public void run() {
time1 = System.currentTimeMillis();
while (true) {
time2 = System.currentTimeMillis();
while (!(minitues == 0 & sound == 0) && time2 >= time1 + 1000) {
time1 = time2;
if (sound == 0) {
sound = 59;
minitues--;
} else {
sound--;
}
LabelTime = this.getTime();
display();
}
if (minitues == 0 && sound == 0) {
dialog.setVisible(true);
onetime = true;
break;
}
}
}
private String getTime() {
if (minitues < 10)
this.Sminitues = "0" + minitues;
else
this.Sminitues = "" + minitues;
if (sound < 10)
this.Ssound = "0" + sound;
else
this.Ssound = "" + sound;
return this.Sminitues + ":" + this.Ssound;
}
public void display() {
/*
* 显示倒计时
*/
l.setText(this.LabelTime);
}
}
}
}
或者在PPT中做,网上有教程。
热心网友 时间:2023-09-24 02:29
整个flash啊,简单,好看,体验好啊,况且还方便,需要的话,给我发信。
hou80houzhu@gmail.com
我给你定制个。