標題:
顯示系統時間 (三)
[打印本頁]
作者:
周政輝
時間:
2018-6-2 11:06
標題:
顯示系統時間 (三)
完成如下圖所示之桌面小時鐘
[attach]4192[/attach]
作者:
張健勳
時間:
2018-6-2 11:16
package bbs.istak.org.tw;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextPane;
public class Main extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Main frame = new Main();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Main() {
setTitle("\u6642\u9418");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 315, 130);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel label = new JLabel("\u73FE\u5728\u6642\u9593\uFF1A");
label.setBounds(14, 13, 83, 19);
contentPane.add(label);
Date date = new Date();
SimpleDateFormat nd24 = new SimpleDateFormat("西元yyyy年 MM月 dd日 , hh時 mm分 ss秒");
JLabel lblNewLabel = new JLabel(nd24.format(date));
lblNewLabel.setLabelFor(lblNewLabel);
lblNewLabel.setBounds(24, 45, 259, 25);
contentPane.add(lblNewLabel);
}
}
複製代碼
作者:
蔡季樺
時間:
2018-6-2 11:17
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
public class Main3 extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Main3 frame = new Main3();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Main3() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
Date d = new Date();
SimpleDateFormat s1 = new SimpleDateFormat("yyyy/MM/dd a hh:mm:ss");
JLabel lblNewLabel = new JLabel(s1.format(d));
lblNewLabel.setBounds(142, 57, 336, 133);
contentPane.add(lblNewLabel);
}
}
複製代碼
作者:
黃茂勛
時間:
2018-6-2 11:21
本帖最後由 黃茂勛 於 2018-6-2 11:43 編輯
package bbs.istak.org.tw;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import java.awt.Color;
import java.awt.SystemColor;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.SwingConstants;
import java.awt.Font;
import javax.swing.JLabel;
public class haung201862 extends JFrame {
private JPanel contentPane;
private JLabel Date;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
haung201862 frame = new haung201862();
frame.setVisible(true);
frame.setTitle("小時鐘");
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public haung201862() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 345, 117);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
Date = new JLabel("");
Date.setHorizontalAlignment(SwingConstants.CENTER);
Date.setFont(new Font("新細明體", Font.PLAIN, 18));
Date.setBounds(25, 10, 280, 65);
contentPane.add(Date);
GetTime();
}
public void GetTime()
{
TimeThread thread = new TimeThread(Date);
thread.start();
}
}
複製代碼
package bbs.istak.org.tw;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JLabel;
public class TimeThread extends Thread{
private JLabel lb = null;
TimeThread(JLabel lb)
{
this.lb = lb;
}
public void run()
{
try {
while(true)
{
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd E a hh:mm:ss ");
String now = sdf.format(d);
Thread.sleep(1000);
lb.setText(now);
}
} catch (InterruptedException e) {
// TODO 自動產生的 catch 區塊
e.printStackTrace();
}
}
}
複製代碼
作者:
陳泓瑜
時間:
2018-6-2 11:25
package tw.kuas.edu.tw;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Toolkit;
import java.awt.Font;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.awt.Color;
public class CTime extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
CTime frame = new CTime();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public CTime() {
setIconImage(Toolkit.getDefaultToolkit().getImage(CTime.class.getResource("/tw/kuas/edu/tw/59252.png")));
setTitle("CLOCK");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 513, 100);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel label = new JLabel("");
label.setForeground(Color.RED);
label.setFont(new Font("Consolas", Font.BOLD, 48));
label.setBounds(0, 0, 519, 62);
contentPane.add(label);
Date time = new Date();
SimpleDateFormat sdt1 = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
label.setText(sdt1.format(time));
}
}
複製代碼
作者:
蔡庭豪
時間:
2018-6-2 11:25
package bbs.istak.org.tw;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.util.Calendar;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
public class clock extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
clock frame = new clock();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public clock() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 164, 128);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("New label");
lblNewLabel.setBounds(10, 10, 128, 70);
contentPane.add(lblNewLabel);
Calendar c = Calendar.getInstance();
SDF sdf = new SDF("yyyy/MM/dd hh:mm:ss");
lblNewLabel.setText(sdf.format(c));
}
}
複製代碼
作者:
蔡庭豪
時間:
2018-6-2 12:02
package bbs.istak.org.tw;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JLabel;
public class TThread extends Thread{
private JLabel label;
public TThread(JLabel label)
{
this.label = label;
}
public void run()
{
while(true)
{
try {
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 E aH時mm分ss秒");
label.setText(sdf.format(d));
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO 自動產生的 catch 區塊
e.printStackTrace();
}
}
}
}
複製代碼
package bbs.istak.org.tw;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.util.Calendar;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
public class Clock extends JFrame {
private JPanel contentPane;
private JLabel time;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Clock frame = new Clock();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Clock() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 315, 128);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
time = new JLabel("New label");
time.setBounds(10, 10, 279, 70);
contentPane.add(time);
Gettime();
}
public void Gettime(){
TThread tt = new TThread(time);
tt.start();
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2