GK SCIENTIST

General Knowledge One Stop Source
Menu
  • Home
  • Social Science
    • History
    • Political Science
    • Geography
  • Science
    • Physics
    • Chemistry
    • Biology
  • Chemistry Notes
  • Mathematics
  • Computer
  • Tutorial MySQL
  • Tutorial Python
  • Java Tutorial
  • English Grammar
  • English Essay
  • Indian Anthropology
  • Philosophy
  • Solved Paper
  • UPSC
  • Current Content
    • Current Affairs
    • RSTV News
    • Yojana and Kurukshetra Gist
  • Donate
  • Contact Us

If you are interested in advertising to our audience, submit the advertising enquiry form.

Advertising Enquiry
Computer

Create a Clock in Java

Gk Scientist January 19, 2023 No Comments
Tweet WhatsApp Telegram

Create a Clock in Java:

We can use the Eclipse IDE for this example. If you do not know about it then follow this link- How to Install Eclipse For Java and create a program in it.

SimpleDateFormat Class– Oracle Docs.

Sample Code to Create a Clock in Java:

java clock app code 1 - Create a Clock in Java
clock in java code - Create a Clock in Java
java digital clock code - Create a Clock in Java

Output:

java clock created - Create a Clock in Java
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class ClockApp extends JFrame{
	
	
	SimpleDateFormat timeFormat;
	SimpleDateFormat dayFormat;
	SimpleDateFormat dateFormat;
	JLabel timeLabel;
	JLabel dayLabel;
	JLabel dateLabel;
	String time;
	String day;
	String date;
	
	ClockApp() {
		
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setTitle("Clock App");
		this.setLayout(new FlowLayout());
		this.setSize(350,250);
		this.setResizable(false);
		
		timeFormat =new SimpleDateFormat("hh:mm:ss a");
		dayFormat =new SimpleDateFormat("EEEE");
		dateFormat =new SimpleDateFormat("MMMM dd, yyyy");
		
		timeLabel = new JLabel();
		timeLabel.setFont(new Font("Roboto",Font.PLAIN,60));
		timeLabel.setForeground(new Color(255,102,102));
		timeLabel.setBackground(Color.black);
		timeLabel.setOpaque(true);
		
		dayLabel = new JLabel();
		dayLabel.setFont(new Font("Gill Sans",Font.PLAIN,40));
		
		
		dateLabel = new JLabel();
		dateLabel.setFont(new Font("Gill Sans",Font.PLAIN,30));
		
		
		this.add(timeLabel);
		this.add(dayLabel);
		this.add(dateLabel);
		this.setVisible(true);
		
		setTime();		
		
	}

	private void setTime() {
		// TODO Auto-generated method stub
		
		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();
		}
		
	    }
		
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		new ClockApp();
 
	}

}

Tutorial MySQL
Tutorial Python
Tokens in C++
Database Management System (DBMS)
Applications of Computer
Basic Components of Computer System
Java (programming language)– Wikipedia
Prev Article
Next Article

Related Articles

Python User-Defined Function
Python User-Defined Function: We can use the PyCharm code editor …
Gk Scientist December 2, 2022 Computer

Python User-Defined Function

Python MySQL Order By and Limit
Python MySQL Order By and Limit: (1) Order By- When …
Gk Scientist December 13, 2022 Computer

Python MySQL Order By and Limit

Create Youtube Video Downloader Using Python
Create Youtube Video Downloader Using Python: We can use the …
Gk Scientist December 18, 2022 Computer

Create Youtube Video Downloader Using Python

Application Software
Application Software: Application software may be defined as the set …
Gk Scientist September 25, 2022 Computer

Application Software

Email (Electronic Mail)
Email: Electronic Mail is sending and receiving messages by a …
Gk Scientist September 16, 2022 Computer

Email (Electronic Mail)

Simple Java GUI (Graphical User Interface)
Simple Java GUI: We can use the Eclipse IDE for …
Gk Scientist December 30, 2022 Computer

Simple Java GUI (Graphical User Interface)

Wired Networking
Wired Networking: Networking that uses a cabling system that guides …
Gk Scientist October 19, 2022 Computer

Wired Networking

Python String format() Method
Python String format() Method: We can use the PyCharm code …
Gk Scientist November 26, 2022 Computer

Python String format() Method

Leave a Reply Cancel Reply

Search




  • Popular
  • Recent




GK SCIENTIST

General Knowledge One Stop Source

Information

  • About Us
  • Terms and Condition, Disclaimer
  • Contact Us

Android Apps

  • IAS App For English Medium Students
  • IAS Basics App For English Medium Students
  • IAS Hindi App For Hindi Medium Students
DMCA.com Protection Status

Popular Tags

Biology (33) Biology Questions (88) Chemistry (57) Computer (213) Current Affairs (4) Current Content (0) Economy (10) English Essay (172) English Grammar (75) English Literature (10) Geography (83) History (259) Indian Anthropology (11) Indian Polity (14) JKAS Mains Question Papers (17) Mathematics (68) Moral Science (7) NCERT & Other Boards Books (25) Philosophy (114) Physics (89) Political Science (132) RS TV News (33) Science (553) Social Anthropology (7) Social Science (17) Solved Paper (47) UPSC (7) UPSC Mains Question Papers (26)

Downloads

  • NCERT Books
  • Old NCERT Books
  • NIOS Books For IAS, SSC, and State PSC Exam
  • Tamil Nadu Board Books: Important For UPSC, SSC, and State PSC Exam
  • Modern Indian and World History Notes For IAS Exam
  • UPSC Topper 2013 Gaurav Agrawal Notes For IAS Preparation
  • UPSC IAS Prelims General Studies – Previous Year Papers
  • UPSC Mains Question Papers

Copyright © 2023 GK SCIENTIST
Theme by MyThemeShop.com& Hosted On Cloudways

Ad Blocker Detected

Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Refresh
 

Loading Comments...