Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from wasifhussain77890/main
Digital clock using java
- Loading branch information
Showing
7 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
</component> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
This program outputs a digital clock . To run this code just copy this | ||
folder to your pc and go to Digital Clock Using Java\src\com\practice and run Main.java in any | ||
java compiler (e.g.聽intellij) | ||
|
||
Tadaa , your output will be on the screen showing current time in | ||
digital format |
Binary file added
BIN
+619 Bytes
JAVA/Digital Clock Using Java/out/production/Digital Clock/com/practice/Main.class
Binary file not shown.
Binary file added
BIN
+1.23 KB
JAVA/Digital Clock Using Java/out/production/Digital Clock/com/practice/MyWindow$1.class
Binary file not shown.
Binary file added
BIN
+1.38 KB
JAVA/Digital Clock Using Java/out/production/Digital Clock/com/practice/MyWindow.class
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.practice; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
System.out.println("Hello"); | ||
MyWindow w = new MyWindow(); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
JAVA/Digital Clock Using Java/src/com/practice/MyWindow.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.practice; | ||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
public class MyWindow extends JFrame { | ||
private JLabel heading; | ||
private JLabel clockLabel; | ||
private Font font = new Font("",Font.BOLD,35); | ||
MyWindow(){ | ||
super.setTitle("My Clock"); | ||
super.setSize(400,400); | ||
super.setLocation(300,50); | ||
this.createGUI(); | ||
this.startClock(); | ||
super.setVisible(true); | ||
} | ||
public void createGUI(){ | ||
|
||
heading = new JLabel("My Clock"); | ||
clockLabel = new JLabel("clock"); | ||
|
||
heading.setFont(font); | ||
clockLabel.setFont(font); | ||
|
||
this.setLayout(new GridLayout(2,1)); | ||
|
||
this.add(heading); | ||
|
||
this.add(clockLabel); | ||
} | ||
public void startClock(){ | ||
// Timer timer = new Timer(1000, new ActionListener() { | ||
// @Override | ||
// public void actionPerformed(ActionEvent e) { | ||
// //String dateTime = new Date().toString(); | ||
// //String dateTime = new Date().toLocaleString(); | ||
// Date d = new Date(); | ||
// | ||
// SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a"); | ||
// String dateTime = sdf.format(d); | ||
// | ||
// clockLabel.setText(dateTime); | ||
// } | ||
// }); | ||
// timer.start(); | ||
|
||
Thread t = new Thread(){ | ||
public void run(){ | ||
try{ | ||
while(true){ | ||
Date d = new Date(); | ||
|
||
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a"); | ||
String dateTime = sdf.format(d); | ||
|
||
clockLabel.setText(dateTime); | ||
|
||
//Thread.sleep(1000); | ||
Thread.currentThread().sleep(1000); | ||
} | ||
}catch (InterruptedException e){ | ||
e.printStackTrace(); | ||
} | ||
} | ||
}; | ||
t.start(); | ||
} | ||
} |