From 5a17a9fd1f82c5317aef896ab2f28f30ff09f474 Mon Sep 17 00:00:00 2001 From: Minty B <111585812+MintyTheCoder@users.noreply.github.com> Date: Sat, 9 Sep 2023 21:40:48 -0400 Subject: [PATCH] Code Clean-up A little bit of clean up to make the code look better --- .../JavaCalculators/ConsoleCalculator.class | Bin 2882 -> 2882 bytes .../bin/JavaCalculators/SwingCalculator.class | Bin 3029 -> 3029 bytes .../JavaCalculators/ConsoleCalculator.java | 4 ---- .../src/JavaCalculators/SwingCalculator.java | 20 +++++++++--------- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/Java Calculators/bin/JavaCalculators/ConsoleCalculator.class b/Java Calculators/bin/JavaCalculators/ConsoleCalculator.class index d845b77b3548a2a4ebad7efea081459fae74a0cb..3b7ae842b8975478f7ac4ca2ded3deeb00540dae 100644 GIT binary patch delta 193 zcmW;AJ8A+^7=Y35HsOj~&}K%v*x3djAcz{QOs3R`b|VPd2!?c>*i2Hrk}nq=}HhChHm9GzFQWOiAWh#`dPVY$~!Zvahnv|6XOQ zvNhQ^+4_BtjgX^USGpzLCPs%x-bwPo69aM#Wk+-w(_=!P89sBiEZDQ;7mpL4ocZF9 YZ!Y{OgRi2jl*L-b*{K8v?;)JO0YtDT3;+NC delta 193 zcmW;By9z;Z9KiAKf6*sSf@8-_XaSRgpNn(+5wPEY5NKPa#QV_9R$0+EcXi2mzTKVfov?^K?wMFYc zz16%$)o2R0gxdt^5T;L*0WpT88PUX%8PjD#k0~2m_RKgj=fZ*qOP;KFvF6QIY4$3> QL75y?h_i}tbv?e!7jHBtm;e9( diff --git a/Java Calculators/bin/JavaCalculators/SwingCalculator.class b/Java Calculators/bin/JavaCalculators/SwingCalculator.class index 012a17e97060f2953958f3ff194006549b1f822a..71c3d5ef1cd3308183b0113ce781b78ee5749fb8 100644 GIT binary patch delta 108 zcmV-y0F(dK7u6TAj|c$?laL5#2@wDc01^Ng02Pw~2{Hi-lQaoI2^atd02u%Y02;G? z2`B*t9{>sfAd{;KJ1sc?lmI#aoB%xlrT{(wvj9H;y8u7{!vH}5%K$SOp@Bm7a6AQwrLKmz6 delta 108 zcmV-y0F(dK7u6TAj|c$>laL5#2@(Jd022Th02Y%02{Hi;lQaoI2^jze02%-Z02{M@ z2`B*tAOH#gA(N{LJ1sZ>lmIyZoB%ukrT{$vvj9E-y8u4`!vH`4%K$+D(*QyM-2g`b O=>SRq@BmAb6AQwsau==u diff --git a/Java Calculators/src/JavaCalculators/ConsoleCalculator.java b/Java Calculators/src/JavaCalculators/ConsoleCalculator.java index dba21b6..1f3b915 100644 --- a/Java Calculators/src/JavaCalculators/ConsoleCalculator.java +++ b/Java Calculators/src/JavaCalculators/ConsoleCalculator.java @@ -47,7 +47,6 @@ public void getNumbers() //creates a method to add the numbers from getNumbers and print the sum in the console public float doSum() { - //getNumbers(); float sum; sum = number1 + number2; System.out.println("The sum of your two numbers is:"); @@ -59,7 +58,6 @@ public float doSum() //creates a method to multiply the numbers from getNumbers and print the product in the console public float doProduct() { - //getNumbers(); float product; product = number1 * number2; System.out.println("The product of your two numbers is:"); @@ -71,7 +69,6 @@ public float doProduct() //creates a method to subtract the numbers from getNumbers and print the difference in the console public float doDifference() { - //getNumbers(); float difference; difference = number1 - number2; System.out.println("The difference between your two numbers is:"); @@ -83,7 +80,6 @@ public float doDifference() //create a method to divide the numbers from getNumbers and print the quotient in the console public float doQuotient() { - //getNumbers(); float quotient; quotient = number1 / number2; System.out.println("The quotient of your two numbers is:"); diff --git a/Java Calculators/src/JavaCalculators/SwingCalculator.java b/Java Calculators/src/JavaCalculators/SwingCalculator.java index 71bed19..83af607 100644 --- a/Java Calculators/src/JavaCalculators/SwingCalculator.java +++ b/Java Calculators/src/JavaCalculators/SwingCalculator.java @@ -1,9 +1,8 @@ package JavaCalculators; import javax.swing.*; - import java.awt.FlowLayout; -//import java.util.Scanner; + import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -12,7 +11,7 @@ public class SwingCalculator { //create a JFrame Object - static JFrame calcBox; + public static JFrame calcBox; //create 2 text boxes for text input static final JTextField intInput1 = new JTextField("Enter Your First Integer"); @@ -28,10 +27,11 @@ public static void main(String[] args) public static void setup() { - // creating a frame object + // creating a frame object calcBox = new JFrame(); calcBox.setSize(500,500); - // creating the buttons + + // creating the buttons JButton addition = new JButton("+"); JButton subtraction = new JButton("-"); JButton multiplication = new JButton("×"); @@ -51,6 +51,7 @@ public static void setup() subtraction.addActionListener(subtractButton); multiplication.addActionListener(multiplyButton); division.addActionListener(divideButton); + //connects Action Listeners to corresponding text fields intInput1.addActionListener(text1); @@ -63,9 +64,7 @@ public static void setup() calcBox.add(subtraction); calcBox.add(multiplication); calcBox.add(division); - calcBox.add(intInput2); - - + calcBox.add(intInput2); //sets the size of the window/GUI calcBox.setSize(300, 300); @@ -73,7 +72,8 @@ public static void setup() //allows the window to be visible calcBox.setVisible(true); } - + + //private inner class to listen for button presses /** Action that will happen when enter is pressed on the TextField*/ private static class TextListener1 implements ActionListener @@ -110,7 +110,7 @@ public void actionPerformed(ActionEvent buttonPress) { //what happens when button is pressed System.out.println("Addition Selected"); - //calculator.doSum(); + JLabel label = new JLabel(" = " + calculator.doSum()); calcBox.add(label);