java時鐘,java時鐘程式

來源:互聯網
上載者:User

java時鐘,java時鐘程式
 一般實現形式

 1 package ares.present; 2  3 import java.awt.event.ActionEvent; 4 import java.awt.event.ActionListener; 5 import java.util.Date; 6  7 public class Printer implements ActionListener { 8  9     @Override10     public void actionPerformed(ActionEvent e) {11         Date date=new Date();12         System.out.println(date);13     }14 }
 1 package ares.present; 2  3 import java.awt.event.ActionListener; 4 import javax.swing.JOptionPane; 5 import javax.swing.Timer; 6  7 public class Main { 8  9     public static void main(String[] args) {10        ActionListener listener= new Printer();11        Timer timer=new Timer(1000,listener);12        timer.start();13        JOptionPane.showMessageDialog(null, "Quit");14        System.exit(0);15     }16 }
升級版(匿名內部類)
 1 package ares.present; 2  3 import java.awt.event.ActionEvent; 4 import java.awt.event.ActionListener; 5 import java.util.Date; 6 import javax.swing.JOptionPane; 7 import javax.swing.Timer; 8  9 public class Main {10 11     public static void main(String[] args) {12         ActionListener listener=new ActionListener() {13             14             @Override15             public void actionPerformed(ActionEvent e) {16                Date date=new Date();17                System.out.println(date);18             }19         };20         21         Timer timer=new Timer(1000,listener);22         timer.start();23         JOptionPane.showMessageDialog(null, "Quit");24         System.exit(0);25     }26 }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.