我正在使用 Java 创建一个简单的网吧管理系统。这是我最后一年的项目,一切都很好。在项目的最后阶段,我遇到了当人坐在电脑上时间开始时它工作正常的问题,我附上了下面的截图。每 15 分钟我需要计算金额 50 我不知道怎么做。到目前为止我尝试了什么,我附在下面。
public gg() {
initComponents();
TimeStart();
T.start();
}
public void TimeStart()
{
Thread t = new Thread()
{
public void run()
{
while(true)
{
DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
Date date = new Date();
Calendar cal = Calendar.getInstance();
txttime.setText(dateFormat.format(cal.getTime()));
try {
Thread.sleep(1);
} catch (InterruptedException ex) {
Logger.getLogger(gg.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
};
t.start();
int sec=0; int min=0; int hour=0;
int Cumvalue = 0;
Timer T = new Timer(1000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
sec++;
txtsec.setText(":" + sec);
if(sec==60)
{
sec=0;
txtsec.setText(":" +0);
min++;
txtmin.setText(":" +min);
if(min >= 15)
{
Cumvalue += 50;
txtam.setText(String.valueOf(Cumvalue));
}
if(hour==60)
{
min=0;
txtmin.setText(":" + 0);
hour++;
txthour.setText(":" +hour);
}
}
}
});
我试过这样
if(min >= 15)
{
Cumvalue += 50;
txtam.setText(String.valueOf(Cumvalue));
}
它没有用
