Skip to content

Commit 4578598

Browse files
PreetamPreetam
Preetam
authored and
Preetam
committed
Added Colors in Button
1 parent 889ceb4 commit 4578598

18 files changed

+178
-104
lines changed

.DS_Store

0 Bytes
Binary file not shown.

Calculator using Java/.idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Calculator using Java/.idea/misc.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Calculator using Java/.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Calculator using Java/.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" packagePrefix="simplejavacalculator" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>

Calculator using Java/Calculator.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package simplejavacalculator;
22

33
import static java.lang.Double.NaN;
4+
import static java.lang.Math.log10;
5+
import static java.lang.Math.pow;
46

5-
import static java.lang.Math.log;
67

7-
import static java.lang.Math.log10;
88

9-
import static java.lang.Math.pow;
109

1110
public class Calculator {
1211

@@ -22,11 +21,11 @@ public enum MonoOperatorModes {
2221

2322
}
2423

25-
private Double num1, num2;
24+
private double num1, num2;
2625

2726
private BiOperatorModes mode = BiOperatorModes.normal;
2827

29-
private Double calculateBiImpl() {
28+
private double calculateBiImpl() {
3029

3130
if (mode == BiOperatorModes.normal) {
3231

@@ -48,7 +47,7 @@ private Double calculateBiImpl() {
4847

4948
if (mode == BiOperatorModes.minus) {
5049

51-
return num1 num2;
50+
return num1 - num2;
5251

5352
}
5453

Calculator-project/.DS_Store

0 Bytes
Binary file not shown.

Calculator-project/.classpath

-17
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,5 @@
2323
<attribute name="maven.pomderived" value="true"/>
2424
</attributes>
2525
</classpathentry>
26-
<classpathentry kind="src" path="target/generated-sources/annotations">
27-
<attributes>
28-
<attribute name="optional" value="true"/>
29-
<attribute name="maven.pomderived" value="true"/>
30-
<attribute name="ignore_optional_problems" value="true"/>
31-
<attribute name="m2e-apt" value="true"/>
32-
</attributes>
33-
</classpathentry>
34-
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
35-
<attributes>
36-
<attribute name="optional" value="true"/>
37-
<attribute name="maven.pomderived" value="true"/>
38-
<attribute name="ignore_optional_problems" value="true"/>
39-
<attribute name="m2e-apt" value="true"/>
40-
<attribute name="test" value="true"/>
41-
</attributes>
42-
</classpathentry>
4326
<classpathentry kind="output" path="target/classes"/>
4427
</classpath>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3+
org.eclipse.jdt.core.compiler.compliance=1.8
4+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
5+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
6+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
7+
org.eclipse.jdt.core.compiler.release=disabled
8+
org.eclipse.jdt.core.compiler.source=1.8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1

Calculator-project/src/.DS_Store

6 KB
Binary file not shown.

Calculator-project/src/main/.DS_Store

6 KB
Binary file not shown.
6 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

Calculator-project/src/main/java/com/houarizegai/calculator/Calculator.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -566,17 +566,17 @@ private void repaintFont() {
566566
btn9.setBackground(Color.WHITE);
567567
btnPoint.setBackground(Color.WHITE);
568568

569-
btnC.setForeground(Color.WHITE);
570-
btnBack.setForeground(Color.WHITE);
571-
btnMod.setForeground(Color.WHITE);
572-
btnDiv.setForeground(Color.WHITE);
573-
btnMul.setForeground(Color.WHITE);
574-
btnSub.setForeground(Color.WHITE);
575-
btnAdd.setForeground(Color.WHITE);
576-
btnEqual.setForeground(Color.WHITE);
577-
btnLog.setForeground(Color.WHITE);
578-
btnPower.setForeground(Color.WHITE);
579-
btnRoot.setForeground(Color.WHITE);
569+
btnC.setForeground(new Color(255, 0, 0));
570+
btnBack.setForeground(new Color(255, 255, 0));
571+
btnMod.setForeground(new Color(0, 128, 0));
572+
btnDiv.setForeground(new Color(170, 51, 106));
573+
btnMul.setForeground(new Color(170, 51, 106));
574+
btnSub.setForeground(new Color(170, 51, 106));
575+
btnAdd.setForeground(new Color(170, 51, 106));
576+
btnEqual.setForeground(new Color(0, 0, 139));
577+
btnLog.setForeground(new Color(170, 51, 106));
578+
btnPower.setForeground(new Color(170, 51, 106));
579+
btnRoot.setForeground(new Color(170, 51, 106));
580580
break;
581581
case "DarkTheme":
582582
final Color primaryDarkColor = new Color(141, 38, 99);

Clock.java

+116-70
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,116 @@
1-
import javax.swing.*;
2-
import java.awt.*;
3-
import java.text.SimpleDateFormat;
4-
import java.util.Calendar;
5-
6-
public class Clock extends JFrame {
7-
8-
Calendar calendar;
9-
SimpleDateFormat timeFormat;
10-
SimpleDateFormat dayFormat;
11-
SimpleDateFormat dateFormat;
12-
13-
JLabel timeLabel;
14-
JLabel dayLabel;
15-
JLabel dateLabel;
16-
String time;
17-
String day;
18-
String date;
19-
Clock() {
20-
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
21-
this.setTitle("Java Digital Clock");
22-
this.setLayout(new FlowLayout());
23-
this.setSize(350, 300);
24-
this.setResizable(false);
25-
26-
timeFormat = new SimpleDateFormat("hh:mm:ss a");
27-
dayFormat=new SimpleDateFormat("EEEE");
28-
dateFormat=new SimpleDateFormat("MMMMM, yyyy");
29-
timeLabel = new JLabel();
30-
timeLabel.setFont(new Font("SANS_SERIF", Font.PLAIN, 59));
31-
timeLabel.setBackground(Color.CYAN);
32-
timeLabel.setForeground(Color.BLACK);
33-
timeLabel.setOpaque(true);
34-
dayLabel=new JLabel();
35-
dayLabel.setFont(new Font("SANS_SERIF",Font.BOLD,34));
36-
37-
dateLabel=new JLabel();
38-
dateLabel.setFont(new Font("SANS_SERIF",Font.BOLD,30));
39-
40-
41-
this.add(timeLabel);
42-
this.add(dayLabel);
43-
this.add(dateLabel);
44-
this.setVisible(true);
45-
46-
setTimer();
47-
}
48-
49-
public void setTimer() {
50-
while (true) {
51-
time = timeFormat.format(Calendar.getInstance().getTime());
52-
timeLabel.setText(time);
53-
54-
day = dayFormat.format(Calendar.getInstance().getTime());
55-
dayLabel.setText(day);
56-
57-
date = dateFormat.format(Calendar.getInstance().getTime());
58-
dateLabel.setText(date);
59-
60-
try {
61-
Thread.sleep(1000);
62-
} catch (Exception e) {
63-
e.getStackTrace();
64-
}
65-
}
66-
}
67-
public static void main(String[] args) {
68-
new Clock();
69-
}
70-
}
1+
import java.awt.Color;
2+
import java.awt.Font;
3+
import java.awt.Graphics;
4+
import java.text.SimpleDateFormat;
5+
import java.util.Date;
6+
import java.util.Locale;
7+
import javax.swing.JFrame;
8+
import javax.swing.JPanel;
9+
public class Clock extends JPanel implements Runnable
10+
{
11+
Thread thread = null;
12+
SimpleDateFormat formatter = new SimpleDateFormat("s", Locale.getDefault());
13+
Date currentDate;
14+
int xcenter = 175, ycenter = 175, lastxs = 0, lastys = 0, lastxm = 0, lastym = 0, lastxh = 0, lastyh = 0;
15+
private void drawStructure(Graphics g) {
16+
g.setFont(new Font("TimesRoman", Font.BOLD, 20));
17+
g.setColor(Color.black);
18+
g.fillOval(xcenter - 150, ycenter - 150, 300, 300);
19+
g.setColor(Color.blue);
20+
g.drawString("abhishek dubey", 113, 300);
21+
g.setColor(Color.green);
22+
g.drawString("9", xcenter - 145, ycenter + 0);
23+
g.drawString("3", xcenter + 135, ycenter + 0);
24+
g.drawString("12", xcenter - 10, ycenter - 130);
25+
g.drawString("6", xcenter - 10, ycenter + 145);
26+
}
27+
public void paint(Graphics g)
28+
{
29+
int xhour, yhour, xminute, yminute, xsecond, ysecond, second, minute, hour;
30+
drawStructure(g);
31+
currentDate = new Date();
32+
formatter.applyPattern("s");
33+
second = Integer.parseInt(formatter.format(currentDate));
34+
formatter.applyPattern("m");
35+
minute = Integer.parseInt(formatter.format(currentDate));
36+
formatter.applyPattern("h");
37+
hour = Integer.parseInt(formatter.format(currentDate));
38+
xsecond = (int)(Math.cos(second * 3.14 f / 30 - 3.14 f / 2) * 120 + xcenter);
39+
ysecond = (int)(Math.sin(second * 3.14 f / 30 - 3.14 f / 2) * 120 + ycenter);
40+
xminute = (int)(Math.cos(minute * 3.14 f / 30 - 3.14 f / 2) * 100 + xcenter);
41+
yminute = (int)(Math.sin(minute * 3.14 f / 30 - 3.14 f / 2) * 100 + ycenter);
42+
xhour = (int)(Math.cos((hour * 30 + minute / 2) * 3.14 f / 180 - 3.14 f / 2) * 80 + xcenter);
43+
yhour = (int)(Math.sin((hour * 30 + minute / 2) * 3.14 f / 180 - 3.14 f / 2) * 80 + ycenter);
44+
// Erase if necessary, and redraw
45+
g.setColor(Color.magenta);
46+
if (xsecond != lastxs || ysecond != lastys)
47+
{
48+
g.drawLine(xcenter, ycenter, lastxs, lastys);
49+
}
50+
if (xminute != lastxm || yminute != lastym)
51+
{
52+
g.drawLine(xcenter, ycenter - 1, lastxm, lastym);
53+
g.drawLine(xcenter - 1, ycenter, lastxm, lastym);
54+
}
55+
if (xhour != lastxh || yhour != lastyh)
56+
{
57+
g.drawLine(xcenter, ycenter - 1, lastxh, lastyh);
58+
g.drawLine(xcenter - 1, ycenter, lastxh, lastyh);
59+
}
60+
g.setColor(Color.magenta);
61+
g.drawLine(xcenter, ycenter, xsecond, ysecond);
62+
g.setColor(Color.red);
63+
g.drawLine(xcenter, ycenter - 1, xminute, yminute);
64+
g.drawLine(xcenter - 1, ycenter, xminute, yminute);
65+
g.setColor(Color.green);
66+
g.drawLine(xcenter, ycenter - 1, xhour, yhour);
67+
g.drawLine(xcenter - 1, ycenter, xhour, yhour);
68+
lastxs = xsecond;
69+
lastys = ysecond;
70+
lastxm = xminute;
71+
lastym = yminute;
72+
lastxh = xhour;
73+
lastyh = yhour;
74+
}
75+
public void start()
76+
{
77+
if (thread == null)
78+
{
79+
thread = new Thread(this);
80+
thread.start();
81+
}
82+
}
83+
public void stop()
84+
{
85+
thread = null;
86+
}
87+
public void run()
88+
{
89+
while (thread != null)
90+
{
91+
try
92+
{
93+
Thread.sleep(100);
94+
}
95+
catch (InterruptedException e) {}
96+
repaint();
97+
}
98+
thread = null;
99+
}
100+
public void update(Graphics g)
101+
{
102+
paint(g);
103+
}
104+
public static void main(String args[])
105+
{
106+
JFrame window = new JFrame();
107+
Color c = new Color(118, 73, 190);
108+
window.setBackground(c);
109+
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
110+
window.setBounds(0, 0, 400, 400);
111+
Clock clock = new Clock();
112+
window.getContentPane().add(clock);
113+
window.setVisible(true);
114+
clock.start();
115+
}
116+
}

0 commit comments

Comments
 (0)