⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 textclock1.java

📁 text clock is ticking
💻 JAVA
字号:


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Calendar;


class TextClock1 extends JFrame {

    private JTextField _timeField;  

    public TextClock1() {
    
        _timeField = new JTextField(5);
        _timeField.setEditable(false);
        _timeField.setFont(new Font("sansserif", Font.PLAIN, 48));

        JPanel content = new JPanel();
        content.setLayout(new FlowLayout());
        content.add(_timeField); 
        
        this.setContentPane(content);
        this.setTitle("Text Clock 1");
        this.pack();
        this.setLocationRelativeTo(null);
        this.setResizable(false);

        javax.swing.Timer t = new javax.swing.Timer(1000, new ClockListener());
        t.start();
    }
    
    
    class ClockListener implements ActionListener {
    	public void actionPerformed(ActionEvent e) {
   
            Calendar now = Calendar.getInstance();
            int h = now.get(Calendar.HOUR_OF_DAY);
            int m = now.get(Calendar.MINUTE);
            int s = now.get(Calendar.SECOND);
            _timeField.setText("" + h + ":" + m + ":" + s);
            
    	}
    }
    
 
    public static void main(String[] args) {
        JFrame clock = new TextClock1();
        clock.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        clock.setVisible(true);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -