init
This commit is contained in:
27
.gitignore
vendored
Normal file
27
.gitignore
vendored
Normal file
@@ -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*
|
||||
3
README.md
Normal file
3
README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Calculator
|
||||
|
||||
A simple calculator implemented in Java, with a GUI written using Spring.
|
||||
14
pom.xml
Normal file
14
pom.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.mycompany</groupId>
|
||||
<artifactId>JavaCalculator</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>18</maven.compiler.source>
|
||||
<maven.compiler.target>18</maven.compiler.target>
|
||||
<exec.mainClass>com.mycompany.javacalculator.JavaCalculator</exec.mainClass>
|
||||
</properties>
|
||||
</project>
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
24
src/main/java/com/mycompany/javacalculator/NumButton.java
Normal file
24
src/main/java/com/mycompany/javacalculator/NumButton.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
0
target/classes/.netbeans_automatic_build
Normal file
0
target/classes/.netbeans_automatic_build
Normal file
@@ -0,0 +1,3 @@
|
||||
com/mycompany/javacalculator/JavaCalculator.class
|
||||
com/mycompany/javacalculator/ButtonRow.class
|
||||
com/mycompany/javacalculator/NumButton.class
|
||||
@@ -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
|
||||
0
target/test-classes/.netbeans_automatic_build
Normal file
0
target/test-classes/.netbeans_automatic_build
Normal file
Reference in New Issue
Block a user