From 1c5f51d7028ed84b17e7f24f365fdebf8c10f46b Mon Sep 17 00:00:00 2001 From: Mikayla Dobson <93477693+innocuous-symmetry@users.noreply.github.com> Date: Thu, 12 Jan 2023 12:46:23 -0600 Subject: [PATCH] init --- .gitignore | 27 ++++++++ README.md | 3 + pom.xml | 14 +++++ .../javacalculator/JavaCalculator.java | 63 +++++++++++++++++++ .../mycompany/javacalculator/NumButton.java | 24 +++++++ target/classes/.netbeans_automatic_build | 0 .../compile/default-compile/createdFiles.lst | 3 + .../compile/default-compile/inputFiles.lst | 3 + target/test-classes/.netbeans_automatic_build | 0 9 files changed, 137 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 pom.xml create mode 100644 src/main/java/com/mycompany/javacalculator/JavaCalculator.java create mode 100644 src/main/java/com/mycompany/javacalculator/NumButton.java create mode 100644 target/classes/.netbeans_automatic_build create mode 100644 target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst create mode 100644 target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst create mode 100644 target/test-classes/.netbeans_automatic_build diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b299cad --- /dev/null +++ b/.gitignore @@ -0,0 +1,27 @@ +# .gitignore format from https://github.com/github/gitignore/blob/main/Java.gitignore + +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see +http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* diff --git a/README.md b/README.md new file mode 100644 index 0000000..6ce5f9c --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Calculator + +A simple calculator implemented in Java, with a GUI written using Spring. diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..574152d --- /dev/null +++ b/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + com.mycompany + JavaCalculator + 1.0-SNAPSHOT + jar + + UTF-8 + 18 + 18 + com.mycompany.javacalculator.JavaCalculator + + \ No newline at end of file diff --git a/src/main/java/com/mycompany/javacalculator/JavaCalculator.java b/src/main/java/com/mycompany/javacalculator/JavaCalculator.java new file mode 100644 index 0000000..bc19c90 --- /dev/null +++ b/src/main/java/com/mycompany/javacalculator/JavaCalculator.java @@ -0,0 +1,63 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + */ + +package com.mycompany.javacalculator; + +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; + +/** + * + * @author mikayladobson + */ +public class JavaCalculator implements ActionListener { + private final JFrame frame; + private final JLabel label; + private final JPanel mainPanel; + + private final NumButton btn1; + private final NumButton btn2; + private final NumButton btn3; + + public JavaCalculator() { + frame = new JFrame(); + label = new JLabel("Initial value"); + + mainPanel = new JPanel(); + mainPanel.setBorder(BorderFactory.createEmptyBorder(100,100,100,100)); + mainPanel.setLayout(new GridLayout(4, 4)); + mainPanel.add(label); + + btn1 = new NumButton(1, this); + btn2 = new NumButton(2, this); + btn3 = new NumButton(3, this); + + mainPanel.add(btn1); + mainPanel.add(btn2); + mainPanel.add(btn3); + + frame.add(mainPanel); + frame.setTitle("Calculator"); + + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.pack(); + frame.setVisible(true); + } + + public static void main(String[] args) { + new JavaCalculator(); + } + + @Override + public void actionPerformed(ActionEvent e) { + NumButton source = (NumButton)e.getSource(); + label.setText(source.getText()); + } +} diff --git a/src/main/java/com/mycompany/javacalculator/NumButton.java b/src/main/java/com/mycompany/javacalculator/NumButton.java new file mode 100644 index 0000000..9fa6590 --- /dev/null +++ b/src/main/java/com/mycompany/javacalculator/NumButton.java @@ -0,0 +1,24 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package com.mycompany.javacalculator; +import javax.swing.JButton; + +/** + * + * @author mikayladobson + */ +public class NumButton extends JButton { + private static int btnValue; + + public NumButton(int btnValue, JavaCalculator calculator) { + this.btnValue = btnValue; + this.addActionListener(calculator); + this.setText(String.valueOf(btnValue)); + } + + public int getValue() { + return this.btnValue; + } +} diff --git a/target/classes/.netbeans_automatic_build b/target/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..217cc9d --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,3 @@ +com/mycompany/javacalculator/JavaCalculator.class +com/mycompany/javacalculator/ButtonRow.class +com/mycompany/javacalculator/NumButton.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..c3d4c2e --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,3 @@ +/Users/mikayladobson/Developer/Java/JavaCalculator/src/main/java/com/mycompany/javacalculator/JavaCalculator.java +/Users/mikayladobson/Developer/Java/JavaCalculator/src/main/java/com/mycompany/javacalculator/ButtonRow.java +/Users/mikayladobson/Developer/Java/JavaCalculator/src/main/java/com/mycompany/javacalculator/NumButton.java diff --git a/target/test-classes/.netbeans_automatic_build b/target/test-classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29