fixed build process and added project configuration files from idea
Some checks failed
Build the Jar / build (push) Failing after 11s

This commit is contained in:
2025-12-14 08:22:47 -06:00
parent d472f6ac5e
commit cfa433fd90
26 changed files with 285 additions and 119 deletions

View File

@@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="C:/Users/S700880/eclipse-workspace/Calc/src/main/java/flatlaf-3.7.jar">
<classpathentry kind="lib" path="C:/Users/S700880/eclipse-workspace/Calc/src/main/java/flatlaf-3.7-javadoc.jar">
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -12,8 +12,43 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Set up JDK 20 - name: Set up JDK 20
uses: actions/setup-java@v5 uses: actions/setup-java@v5
with: with:
java-version: '20' java-version: '20'
distribution: 'temurin' distribution: 'temurin'
- name: Create output directories
run: |
mkdir -p out/production/Calc
mkdir -p dist
- name: Compile Java files
run: |
javac -encoding UTF-8 -cp "lib/flatlaf-3.7.jar" -d out/production/Calc \
$(find src/main/java -name "*.java")
- name: Copy resources
run: |
if [ -d "src/main/resources" ]; then
cp -r src/main/resources/* out/production/Calc/ 2>/dev/null || true
fi
- name: Create manifest
run: |
echo "Manifest-Version: 1.0" > manifest.txt
echo "Main-Class: dev.sillyangel.calc.Calculator" >> manifest.txt
echo "Class-Path: lib/flatlaf-3.7.jar" >> manifest.txt
- name: Create JAR
run: |
cd out/production/Calc
jar cfm ../../../dist/CalcShortforCalculator.jar ../../../manifest.txt .
cd ../../..
- name: Upload JAR artifact
uses: actions/upload-artifact@v4
with:
name: CalcShortforCalculator
path: dist/CalcShortforCalculator.jar

10
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,10 @@
# Default ignored files
/shelf/
/workspace.xml
# Ignored default folder with query files
/queries/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

6
.idea/copilot.data.migration.agent.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AgentMigrationStateService">
<option name="migrationStatus" value="COMPLETED" />
</component>
</project>

6
.idea/copilot.data.migration.ask.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AskMigrationStateService">
<option name="migrationStatus" value="COMPLETED" />
</component>
</project>

6
.idea/copilot.data.migration.edit.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EditMigrationStateService">
<option name="migrationStatus" value="COMPLETED" />
</component>
</project>

7
.idea/discord.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="APPLICATION" />
<option name="description" value="" />
</component>
</project>

10
.idea/libraries/lib.xml generated Normal file
View File

@@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="lib">
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/flatlaf-3.7.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/flatlaf-3.7-javadoc.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

6
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_20" project-jdk-name="temurin-20" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Calc.iml" filepath="$PROJECT_DIR$/Calc.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>CalculatorButBetter</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1763046761202</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>

View File

@@ -1,2 +0,0 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

View File

@@ -1,12 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=20
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=20
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=20

15
Calc.iml Normal file
View File

@@ -0,0 +1,15 @@
<?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/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/.gitea" />
<excludeFolder url="file://$MODULE_DIR$/.idea" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lib" level="project" />
</component>
</module>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

View File

@@ -44,7 +44,7 @@ public class Calculator extends JFrame implements KeyListener {
protected double result; protected double result;
private String[] CalculatorModes = new String[] {"Standard", "Scientific", "Data calculation"}; private String[] CalculatorModes = new String[] {"Standard", "Scientific", "Data calculation"};
private JComboBox<String> modeselect; private JComboBox<String> modeselect;
public static void main(String[] args) { public static void main(String[] args) {
FlatMacDarkLaf.setup(); FlatMacDarkLaf.setup();
try { try {
@@ -76,22 +76,22 @@ public class Calculator extends JFrame implements KeyListener {
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("/images/appIcon512.png"))); icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("/images/appIcon512.png")));
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("/images/appIcon1024.png"))); icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("/images/appIcon1024.png")));
setIconImages(icons); setIconImages(icons);
setTitle("angel's awesome calculator"); setTitle("angel's awesome calculator");
setBounds(100, 100, 368, 556); setBounds(100, 100, 368, 556);
setFocusable(true); setFocusable(true);
addKeyListener(this); addKeyListener(this);
contentPane = new JPanel(); contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane); setContentPane(contentPane);
display = new JTextField(); display = new JTextField();
display.setEditable(false); display.setEditable(false);
display.setFont(new Font("Segoe UI", Font.PLAIN, 22)); display.setFont(new Font("Segoe UI", Font.PLAIN, 22));
display.setColumns(10); display.setColumns(10);
JPanel buttonPanel = new JPanel(); JPanel buttonPanel = new JPanel();
addComponentListener(new ComponentAdapter() { addComponentListener(new ComponentAdapter() {
@Override @Override
public void componentResized(ComponentEvent e) { public void componentResized(ComponentEvent e) {
@@ -99,7 +99,7 @@ public class Calculator extends JFrame implements KeyListener {
System.out.println("Window resized to " + size.width + "x" + size.height); System.out.println("Window resized to " + size.width + "x" + size.height);
} }
}); });
JPanel panel = new JPanel(); JPanel panel = new JPanel();
GroupLayout gl_contentPane = new GroupLayout(contentPane); GroupLayout gl_contentPane = new GroupLayout(contentPane);
gl_contentPane.setHorizontalGroup( gl_contentPane.setHorizontalGroup(
@@ -119,10 +119,10 @@ public class Calculator extends JFrame implements KeyListener {
.addPreferredGap(ComponentPlacement.RELATED) .addPreferredGap(ComponentPlacement.RELATED)
.addComponent(display, GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE) .addComponent(display, GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE)
.addGap(27) .addGap(27)
.addComponent(buttonPanel, GroupLayout.PREFERRED_SIZE, 359, GroupLayout.PREFERRED_SIZE) .addComponent(buttonPanel, GroupLayout.PREFERRED_SIZE, 359, GroupLayout.PREFERRED_SIZE)
.addContainerGap(199, Short.MAX_VALUE)) .addContainerGap(199, Short.MAX_VALUE))
); );
buttonPanel.setLayout(new GridLayout(0, 4, 0, 0)); buttonPanel.setLayout(new GridLayout(0, 4, 0, 0));
modeselect = new JComboBox<>(CalculatorModes); modeselect = new JComboBox<>(CalculatorModes);
@@ -134,22 +134,26 @@ public class Calculator extends JFrame implements KeyListener {
} }
}); });
modeselect.setEditable(false); modeselect.setEditable(false);
modeselect.setFocusable(false);
JButton btnNewButton_1 = new JButton("New button");
JLabel lblNewLabel = new JLabel("New label"); JButton btnNewButton_1 = new JButton("New button");
btnNewButton_1.setFocusable(false);
JLabel lblNewLabel = new JLabel("New label");
lblNewLabel.setFocusable(false);
panel.add(modeselect); panel.add(modeselect);
panel.add(lblNewLabel); panel.add(lblNewLabel);
panel.add(btnNewButton_1); panel.add(btnNewButton_1);
JButton empty_4 = new JButton(""); JButton btnPercent = new JButton("%");
JButton empty_1 = new JButton(""); JButton btnClearEntry = new JButton("CE");
JButton empty_2 = new JButton(""); JButton btnReciprocal = new JButton("1/x");
JButton empty = new JButton(""); JButton btnSquare = new JButton("");
JButton empty_3 = new JButton(""); JButton btnSquareRoot = new JButton("√x");
JButton btnErase = new JButton("DEL"); // Use FlatLaf Tree.icon.collapsed as backspace-like icon (or just use text)
JButton btnBackspace = new JButton("");
JButton btnClear = new JButton("C"); JButton btnClear = new JButton("C");
JButton btnPlusMin = new JButton("+/-"); JButton btnPlusMin = new JButton("+/-");
JButton btnDot = new JButton("."); JButton btnDot = new JButton(".");
@@ -162,7 +166,7 @@ public class Calculator extends JFrame implements KeyListener {
JButton btn4 = new JButton("4"); JButton btn4 = new JButton("4");
JButton btn5 = new JButton("5"); JButton btn5 = new JButton("5");
JButton btn6 = new JButton("6"); // why was 6 afraid of 7... because 7 8 9 :sob: JButton btn6 = new JButton("6"); // why was 6 afraid of 7... because 7 8 9 :sob:
JButton btn7 = new JButton("7"); // 67! JButton btn7 = new JButton("7"); // 67!
JButton btn8 = new JButton("8"); JButton btn8 = new JButton("8");
JButton btn9 = new JButton("9"); JButton btn9 = new JButton("9");
@@ -174,9 +178,9 @@ public class Calculator extends JFrame implements KeyListener {
btnDot.addActionListener(new ActionListener() { btnDot.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
String n = display.getText(); // get the text on the display String n = display.getText(); // get the text on the display
if (n.contains(".")) return; // if it already contains a "." skip rest of this if (n.contains(".")) return; // if it already contains a "." skip rest of this
processDigit(e.getActionCommand()); processDigit(e.getActionCommand());
} }
}); });
@@ -185,19 +189,25 @@ public class Calculator extends JFrame implements KeyListener {
math(); math();
} }
}); });
btnErase.addActionListener(new ActionListener() { btnBackspace.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
clear(); backspace();
} }
}); });
btnClearEntry.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
clearEntry();
}
});
btnClear.addActionListener(new ActionListener() { btnClear.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
clear(); clearAll();
} }
}); });
btnPlus.addActionListener(new ActionListener() { btnPlus.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
setOperator(e.getActionCommand()); setOperator(e.getActionCommand());
@@ -208,8 +218,8 @@ public class Calculator extends JFrame implements KeyListener {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
setOperator(e.getActionCommand()); setOperator(e.getActionCommand());
} }
}); });
btnMul.addActionListener(new ActionListener() { btnMul.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
setOperator(e.getActionCommand()); setOperator(e.getActionCommand());
@@ -245,13 +255,13 @@ public class Calculator extends JFrame implements KeyListener {
processDigit(e.getActionCommand()); processDigit(e.getActionCommand());
} }
}); });
btn4.addActionListener(new ActionListener() { btn4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
processDigit(e.getActionCommand()); processDigit(e.getActionCommand());
} }
}); });
btn5.addActionListener(new ActionListener() { btn5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
processDigit(e.getActionCommand()); processDigit(e.getActionCommand());
@@ -268,37 +278,62 @@ public class Calculator extends JFrame implements KeyListener {
processDigit(e.getActionCommand()); processDigit(e.getActionCommand());
} }
}); });
btn8.addActionListener(new ActionListener() { btn8.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
processDigit(e.getActionCommand()); processDigit(e.getActionCommand());
} }
}); });
btn9.addActionListener(new ActionListener() { btn9.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
processDigit(e.getActionCommand()); processDigit(e.getActionCommand());
} }
}); });
btnPlusMin.addActionListener(new ActionListener() { btnPlusMin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
String tmp = display.getText(); String tmp = display.getText();
if (tmp == null || tmp.isEmpty()) return; if (tmp == null || tmp.isEmpty()) return;
char first = tmp.charAt(0); char first = tmp.charAt(0);
if (first == '-') { if (first == '-') {
tmp = tmp.substring(1, tmp.length()); tmp = tmp.substring(1, tmp.length());
display.setText(tmp); display.setText(tmp);
} else { } else {
display.setText("-" + tmp); display.setText("-" + tmp);
} }
} }
}); });
btnErase.setFont(new Font("Segoe UI", Font.PLAIN, 29)); btnPercent.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setOperator("%");
}
});
btnReciprocal.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
reciprocal();
}
});
btnSquare.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
square();
}
});
btnSquareRoot.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
squareRoot();
}
});
btnBackspace.setFont(new Font("Segoe UI", Font.PLAIN, 29));
btnClear.setFont(new Font("Segoe UI", Font.PLAIN, 29)); btnClear.setFont(new Font("Segoe UI", Font.PLAIN, 29));
btnClearEntry.setFont(new Font("Segoe UI", Font.PLAIN, 29));
btnPlusMin.setFont(new Font("Segoe UI", Font.PLAIN, 29)); btnPlusMin.setFont(new Font("Segoe UI", Font.PLAIN, 29));
btnEq.setFont(new Font("Segoe UI", Font.PLAIN, 29)); btnEq.setFont(new Font("Segoe UI", Font.PLAIN, 29));
btnDot.setFont(new Font("Segoe UI", Font.PLAIN, 29)); btnDot.setFont(new Font("Segoe UI", Font.PLAIN, 29));
@@ -316,20 +351,44 @@ public class Calculator extends JFrame implements KeyListener {
btnMin.setFont(new Font("Segoe UI", Font.PLAIN, 29)); btnMin.setFont(new Font("Segoe UI", Font.PLAIN, 29));
btnDiv.setFont(new Font("Segoe UI", Font.PLAIN, 29)); btnDiv.setFont(new Font("Segoe UI", Font.PLAIN, 29));
btnPlus.setFont(new Font("Segoe UI", Font.PLAIN, 29)); btnPlus.setFont(new Font("Segoe UI", Font.PLAIN, 29));
btnPercent.setFont(new Font("Segoe UI", Font.PLAIN, 29));
btnReciprocal.setFont(new Font("Segoe UI", Font.PLAIN, 29));
btnSquare.setFont(new Font("Segoe UI", Font.PLAIN, 29));
btnSquareRoot.setFont(new Font("Segoe UI", Font.PLAIN, 29));
empty.setEnabled(false); // Make all buttons non-focusable so keyboard input always goes to the frame
empty_1.setEnabled(false); btnBackspace.setFocusable(false);
empty_2.setEnabled(false); btnClear.setFocusable(false);
empty_3.setEnabled(false); btnClearEntry.setFocusable(false);
empty_4.setEnabled(false); btnPlusMin.setFocusable(false);
btnEq.setFocusable(false);
btnDot.setFocusable(false);
btn0.setFocusable(false);
btn1.setFocusable(false);
btn2.setFocusable(false);
btn3.setFocusable(false);
btn4.setFocusable(false);
btn5.setFocusable(false);
btn6.setFocusable(false);
btn7.setFocusable(false);
btn8.setFocusable(false);
btn9.setFocusable(false);
btnMul.setFocusable(false);
btnMin.setFocusable(false);
btnDiv.setFocusable(false);
btnPlus.setFocusable(false);
btnPercent.setFocusable(false);
btnReciprocal.setFocusable(false);
btnSquare.setFocusable(false);
btnSquareRoot.setFocusable(false);
buttonPanel.add(empty); buttonPanel.add(btnPercent);
buttonPanel.add(empty_3); buttonPanel.add(btnClearEntry);
buttonPanel.add(btnClear); buttonPanel.add(btnClear);
buttonPanel.add(btnErase); buttonPanel.add(btnBackspace);
buttonPanel.add(empty_4); buttonPanel.add(btnReciprocal);
buttonPanel.add(empty_1); buttonPanel.add(btnSquare);
buttonPanel.add(empty_2); buttonPanel.add(btnSquareRoot);
buttonPanel.add(btnDiv); buttonPanel.add(btnDiv);
buttonPanel.add(btn7); buttonPanel.add(btn7);
buttonPanel.add(btn8); buttonPanel.add(btn8);
@@ -347,7 +406,7 @@ public class Calculator extends JFrame implements KeyListener {
buttonPanel.add(btn0); buttonPanel.add(btn0);
buttonPanel.add(btnDot); buttonPanel.add(btnDot);
buttonPanel.add(btnEq); buttonPanel.add(btnEq);
contentPane.setLayout(gl_contentPane); contentPane.setLayout(gl_contentPane);
} }
@@ -362,7 +421,7 @@ public class Calculator extends JFrame implements KeyListener {
} }
} }
void clear() { void backspace() {
String tmp = display.getText(); String tmp = display.getText();
if (tmp.length()>1) // if there is more than 1 character if (tmp.length()>1) // if there is more than 1 character
display.setText( tmp.substring(0, tmp.length()-1) ); display.setText( tmp.substring(0, tmp.length()-1) );
@@ -370,11 +429,56 @@ public class Calculator extends JFrame implements KeyListener {
display.setText(""); display.setText("");
} }
void clearEntry() {
// Clear only the current display (entry)
display.setText("");
}
void clearAll() {
// Clear everything including operands and operator
display.setText("");
operand1 = "";
operand2 = "";
operator = "";
resultVisible = false;
}
void reciprocal() {
String tmp = display.getText();
if (tmp == null || tmp.isEmpty()) return;
double value = Double.parseDouble(tmp);
if (value != 0) {
result = 1.0 / value;
display.setText("" + result);
resultVisible = true;
}
}
void square() {
String tmp = display.getText();
if (tmp == null || tmp.isEmpty()) return;
double value = Double.parseDouble(tmp);
result = value * value;
display.setText("" + result);
resultVisible = true;
}
void squareRoot() {
String tmp = display.getText();
if (tmp == null || tmp.isEmpty()) return;
double value = Double.parseDouble(tmp);
if (value >= 0) {
result = Math.sqrt(value);
display.setText("" + result);
resultVisible = true;
}
}
void processDigit(String actionCommand) { void processDigit(String actionCommand) {
if (resultVisible == true) { if (resultVisible == true) {
display.setText(""); display.setText("");
resultVisible = false; resultVisible = false;
} }
// if (actionCommand == "+") { // if (actionCommand == "+") {
// btnDiv.setForeground(new Color(0, 0, 0)); // btnDiv.setForeground(new Color(0, 0, 0));
// btnMul.setForeground(new Color(0, 0, 0)); // btnMul.setForeground(new Color(0, 0, 0));
@@ -397,19 +501,19 @@ public class Calculator extends JFrame implements KeyListener {
// btnMin.setForeground(new Color(30, 144, 255)); // btnMin.setForeground(new Color(30, 144, 255));
// } // }
display.setText(display.getText() + actionCommand); display.setText(display.getText() + actionCommand);
} }
void setOperator(String daop) { void setOperator(String daop) {
operand1 = display.getText(); operand1 = display.getText();
operator = daop; operator = daop;
display.setText(""); display.setText("");
} }
void math() { void math() {
operand2 = display.getText(); operand2 = display.getText();
double op1 = Double.parseDouble(operand1); double op1 = Double.parseDouble(operand1);
double op2 = Double.parseDouble(operand2); double op2 = Double.parseDouble(operand2);
if (operator == "+") { if (operator == "+") {
result = op1+op2; result = op1+op2;
} else if (operator == "-") { } else if (operator == "-") {
@@ -418,25 +522,27 @@ public class Calculator extends JFrame implements KeyListener {
result = op1*op2; result = op1*op2;
} else if (operator == "/") { } else if (operator == "/") {
result = op1/op2; result = op1/op2;
} else if (operator == "%") {
result = op1 % op2;
} else { } else {
result = op2; result = op2;
System.out.println("Op: " + op1); System.out.println("Op: " + op1);
System.out.println("Op2: " + op2); System.out.println("Op2: " + op2);
} }
operator = ""; operator = "";
operand1 = ""; operand1 = "";
operand2 = ""; operand2 = "";
// btnDiv.setForeground(new Color(0, 0, 0)); // btnDiv.setForeground(new Color(0, 0, 0));
// btnMul.setForeground(new Color(0, 0, 0)); // btnMul.setForeground(new Color(0, 0, 0));
// btnPlus.setForeground(new Color(0, 0, 0)); // btnPlus.setForeground(new Color(0, 0, 0));
// btnMin.setForeground(new Color(0, 0, 0)); // btnMin.setForeground(new Color(0, 0, 0));
resultVisible = true; resultVisible = true;
display.setText(""+result); display.setText(""+result);
} }
// Implement the keyPressed method // Implement the keyPressed method
@Override @Override
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {
@@ -445,14 +551,14 @@ public class Calculator extends JFrame implements KeyListener {
if (KeyEvent.getKeyText(keyCode) == "Enter") { if (KeyEvent.getKeyText(keyCode) == "Enter") {
math(); math();
} else if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) { } else if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
clear(); backspace();
} }
} }
// Implement the keyReleased method // Implement the keyReleased method
@Override @Override
public void keyReleased(KeyEvent e) { public void keyReleased(KeyEvent e) {
// int keyCode = e.getKeyCode(); // int keyCode = e.getKeyCode();
// System.out.println("Key Released: " + KeyEvent.getKeyText(keyCode)); // System.out.println("Key Released: " + KeyEvent.getKeyText(keyCode));
} }
@@ -477,6 +583,6 @@ public class Calculator extends JFrame implements KeyListener {
if (c == '=') { if (c == '=') {
math(); math();
} }
} }
} }

Binary file not shown.