logo资料库

java倒计时器代码.docx

第1页 / 共3页
第2页 / 共3页
第3页 / 共3页
资料共3页,全文预览结束
package zuoye; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Calendar; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; public class Daoxu extends JFrame { int count; String[] m = null; int[]sum = null; boolean flag = true; JPanel panel = null; JTextField text = null; JButton button1 = null; MyThread thread = null; Thread t = null; Daoxu(){ init(); this.setTitle("倒计时"); this.setDefaultCloseOperation(this.EXIT_ON_CLOSE); this.pack(); this.setVisible(true); } void init(){ panel = new JPanel(); text = new JTextField(10); MyAction e =new MyAction(); button1 = new JButton("倒计时开始"); button1.addActionListener(e); thread = new MyThread(); t = new Thread(thread); panel.add(text); panel.add(button1); this.add(panel); }
class MyThread implements Runnable{ @Override public void run() { // TODO Auto-generated method stub try { while(true){ sum[1]--; Thread.sleep(1); } } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } class MyAction implements ActionListener{ @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(e.getSource() == button1) { m = text.getText().split(":"); sum = new int[3]; for(int i = 0;i
package zuoye; public class DemoForDaoxu { /** * @param args */ public static void main(String[] args) { new Daoxu(); } }
分享到:
收藏