Java clock app 🕓

Published: 06 September 2020
on channel: Bro Code
80,974
2.3k

Java, clock, program, app, swing, GUI, tutorial, beginners,

#Java #clock #program #app #swing #GUI #tutorial #beginners

//https://docs.oracle.com/javase/7/docs...
//---------------------------------------------------------------
public class Main {

public static void main(String[] args) {

new MyFrame();
}
}
//---------------------------------------------------------------
import java.awt.*;
import java.text.*;
import java.util.*;
import javax.swing.*;

public class MyFrame extends JFrame{

Calendar calendar;
SimpleDateFormat timeFormat;
SimpleDateFormat dayFormat;
SimpleDateFormat dateFormat;
JLabel timeLabel;
JLabel dayLabel;
JLabel dateLabel;
String time;
String day;
String date;

MyFrame(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("My Clock Program");
this.setLayout(new FlowLayout());
this.setSize(350,200);
this.setResizable(false);

timeFormat = new SimpleDateFormat("hh:mm:ss a");
dayFormat = new SimpleDateFormat("EEEE");
dateFormat = new SimpleDateFormat("MMMMM dd, yyyy");

timeLabel = new JLabel();
timeLabel.setFont(new Font("Verdana",Font.PLAIN,50));
timeLabel.setForeground(new Color(0x00FF00));
timeLabel.setBackground(Color.black);
timeLabel.setOpaque(true);

dayLabel = new JLabel();
dayLabel.setFont(new Font("Ink Free",Font.PLAIN,35));

dateLabel = new JLabel();
dateLabel.setFont(new Font("Ink Free",Font.PLAIN,25));


this.add(timeLabel);
this.add(dayLabel);
this.add(dateLabel);
this.setVisible(true);

setTime();
}

public void setTime() {
while(true) {
time = timeFormat.format(Calendar.getInstance().getTime());
timeLabel.setText(time);

day = dayFormat.format(Calendar.getInstance().getTime());
dayLabel.setText(day);

date = dateFormat.format(Calendar.getInstance().getTime());
dateLabel.setText(date);

try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
//---------------------------------------------------------------


On this page of the site you can watch the video online Java clock app 🕓 with a duration of hours minute second in good quality, which was uploaded by the user Bro Code 06 September 2020, share the link with friends and acquaintances, this video has already been watched 80,974 times on youtube and it was liked by 2.3 thousand viewers. Enjoy your viewing!