用JAVA做一个5分钟倒数计时的计时器。并且需要添加背景和文字框。Q391150444 。~ 求高手解答。~

做好了的程序也可以。或者你教我应该怎么弄。要求:全屏显示、可以自己添加背景(或者我把背景给你你帮我添加)、显示有分有秒,有 开始计时、暂停、继续计时、重置4个按钮。 (我们公司要弄一场小型的招聘会,每个选手有5分钟的答题时间,做的不能太简陋或者粗糙,要薪酬的加Q谈

第1个回答  2012-05-27

这样的?

如果是,留下邮件,采纳即发。

第2个回答  2012-06-04
package chaper5;

import java.awt.Font;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.JButton;

import javax.swing.AbstractButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import lx11.Clock;

public class TestClock extends JFrame implements ActionListener{

/**
* @param args
*/
Thread t;
Clock label_1 = new Clock(0,1,0);
int h,m,s;boolean bz=true;
public TestClock() {
super();
getContentPane().setLayout(null);

final JLabel label = new JLabel();
label.setFont(new Font("", Font.BOLD, 18));
label.setBounds(71, 75, 84, 34);
label.setText("倒计时:");
getContentPane().add(label);

label_1.setBounds(145, 75, 167, 34);
label_1.setFont(new Font("", Font.BOLD, 15));
getContentPane().add(label_1);

final JButton button = new JButton();
button.setFont(new Font("", Font.PLAIN, 15));
button.setText("开始");
button.setBounds(135, 140, 99, 23);
getContentPane().add(button);
button.addActionListener(this);
this.setSize(400, 400);
this.setVisible(true);
}

public static void main(String[] args) {
// TODO 自动生成方法存根
new TestClock();

}

public void actionPerformed(ActionEvent arg0) {
// TODO 自动生成方法存根
label_1.bz=true;label_1.h=0;label_1.m=1;label_1.s=0;
t=new Thread(label_1); t.start();
}
public void actionPerformed1(ActionEvent e){
int spendTime = 0;
int i = spendTime++;
int showTime =1-spendTime;
AbstractButton label = null;
label.setText("倒计时:");
}
public void keyReleased(KeyEvent e){
PersonInMaze person=(PersonInMaze)e.getSource();
int m=-1,n=-1;
MazePoint endPoint=person.getAtMazePoint();
if(endPoint.getWallOrRoad().getIsOut()){
Thread recordTime = null;
recordTime.stop();
JOptionPane.showMessageDialog(this,"您成功了!","消息框",
JOptionPane.INFORMATION_MESSAGE );

}
}
public void keyTyped(KeyEvent e) {}
}
第3个回答  2012-05-28
参考这个:
package chn1;

import java.awt.EventQueue;

public class ExamCountDown extends JFrame implements Runnable{

/**
*
*/
private static final long serialVersionUID = 1L;
private boolean flag = true;
private boolean flag1 = true;
private JPanel contentPane;
private Timer timer;
private JTextArea textArea;
private String string = "02:00:00";
private int []intArray;
private JButton button;

/**
* Launch the application.
*/
public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ExamCountDown frame = new ExamCountDown();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the frame.
*/
public ExamCountDown() {
String []stringArray = string.split(":");
intArray = new int[3];
for(int i = 0;i < stringArray.length;i++){
intArray[i] = Integer.parseInt(stringArray[i]);
}
setTitle("\u8003\u8BD5\u65F6\u95F4\u5012\u8BA1\u65F6");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
JLabel label = new JLabel("\u5269\u4F59\u65F6\u95F4\uFF1A");
label.setFont(new Font("宋体", Font.BOLD, 27));
textArea = new JTextArea();
textArea.setText(string);
textArea.setFont(new Font("宋体", Font.BOLD, 27));
timer = new Timer();
button = new JButton("开始");
button.addActionListener(new ActionListener(){

@Override
public void actionPerformed(ActionEvent e) {
timer = new Timer();
textArea.setText(string);
flag = true;
flag1 = true;
// TODO Auto-generated method stub
timer.schedule(new Task(),0, 1000);
button.setEnabled(false);
string = "02:00:00";
}
});
JButton button_1 = new JButton("暂停");
button_1.addActionListener(new ActionListener(){

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
try {
flag = false;
} catch (Exception e1) {
// TODO: handle exception
}

}});

JButton button_2 = new JButton("继续");
button_2.addActionListener(new ActionListener(){

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
flag = true;
}

});
GroupLayout groupLayout = new GroupLayout(contentPane);
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(35, 35, 35)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(label)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(textArea, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGroup(groupLayout.createSequentialGroup()
.addComponent(button)
.addGap(47, 47, 47)
.addComponent(button_1)
.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(button_2)))
.addContainerGap(101, Short.MAX_VALUE))
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(58, 58, 58)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(label)
.addComponent(textArea, GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE))
.addGap(64, 64, 64)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(button)
.addComponent(button_1)
.addComponent(button_2))
.addContainerGap(76, Short.MAX_VALUE))
);
contentPane.setLayout(groupLayout);
}

public JTextArea getTextArea() {
return textArea;
}

public void setTextArea(JTextArea textArea) {
this.textArea = textArea;
}
class Task extends TimerTask{
String string1 = string;
DecimalFormat decimalFormat = new DecimalFormat("00");
public void run() {
if(flag1 == false){
return;
}
// TODO Auto-generated method stub
if(flag == true){
intArray[2] -= 1;
if(intArray[2] < 0)
{
intArray[1] -= 1;
intArray[2] += 60;
if(intArray[1] < 0)
{
intArray[0] -= 1;
intArray[1] += 60;

}
}
if(intArray[0] <= 0 && intArray[1] <= 0
&& intArray[2] <= 0)
{
flag1 = false;

button.setEnabled(true);
timer.cancel();
string = new String(intArray[0] + ":" + intArray[1]
+ ":" + intArray[2]);
string = String.format("%02d:%02d:%02d", intArray[0],intArray[1],intArray[2]);
textArea.setText(string);
string = "02:00:00";
String []stringArray = string.split(":");
intArray = new int[3];
for(int i = 0;i < stringArray.length;i++){
intArray[i] = Integer.parseInt(stringArray[i]);
}
return;
}
string = String.format("%02d:%02d:%02d", intArray[0],intArray[1],intArray[2]);
textArea.setText(string);
}
}
}
@Override
public void run() {
// TODO Auto-generated method stub

}
}本回答被提问者采纳
相似回答