3个回答
展开全部
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Test extends JFrame
{
private JButton btn = new JButton("Start");
private JLabel label = new JLabel();
private int time = 90;
Test() {
setSize(500,300);
setLayout(new FlowLayout());
add(btn);
add(label);
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new Thread(new MyThread()).start();
}
});
setVisible(true);
}
class MyThread implements Runnable
{
public void run() {
while (time > 0)
{
time--;
label.setText(time + "");
try
{
Thread.sleep(1000);
}
catch (Exception e)
{
e.printStackTrace();
}
}
Test.this.dispose();
}
};
public static void main(String[] args)
{
new Test();
}
}
import java.awt.event.*;
import java.awt.*;
public class Test extends JFrame
{
private JButton btn = new JButton("Start");
private JLabel label = new JLabel();
private int time = 90;
Test() {
setSize(500,300);
setLayout(new FlowLayout());
add(btn);
add(label);
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new Thread(new MyThread()).start();
}
});
setVisible(true);
}
class MyThread implements Runnable
{
public void run() {
while (time > 0)
{
time--;
label.setText(time + "");
try
{
Thread.sleep(1000);
}
catch (Exception e)
{
e.printStackTrace();
}
}
Test.this.dispose();
}
};
public static void main(String[] args)
{
new Test();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询