Update src/main/java/dev/sillyangel/calc/Calculator.java
All checks were successful
Build the Jar / build (push) Successful in 7s
All checks were successful
Build the Jar / build (push) Successful in 7s
This commit is contained in:
@@ -1,33 +1,24 @@
|
||||
package dev.sillyangel.calc;
|
||||
|
||||
import dev.sillyangel.calc.themes.MacDarkRed;
|
||||
import dev.sillyangel.calc.CalculatorModes;
|
||||
import java.awt.EventQueue;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.GroupLayout;
|
||||
import javax.swing.GroupLayout.Alignment;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.JComboBox;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Image;
|
||||
import javax.swing.JButton;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Toolkit;
|
||||
//a b c d e f g h i j k l m n o p q r s t u v w x y z
|
||||
// java to javax, com, dev
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.time.Year;
|
||||
import java.net.URISyntaxException;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.LayoutStyle.ComponentPlacement;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.GroupLayout;
|
||||
import javax.swing.GroupLayout.Alignment;
|
||||
import javax.swing.*;
|
||||
import com.formdev.flatlaf.FlatClientProperties;
|
||||
import dev.sillyangel.calc.themes.*;
|
||||
import dev.sillyangel.calc.CalculatorModes;
|
||||
|
||||
|
||||
public class Calculator extends JFrame implements KeyListener {
|
||||
|
||||
@@ -49,7 +40,8 @@ public class Calculator extends JFrame implements KeyListener {
|
||||
public static void main(String[] args) {
|
||||
// IntelliJTheme.setup(Calculator.class.getResourceAsStream("/DarkPurple.theme.json"));
|
||||
// FlatMacDarkLaf.setup();
|
||||
MacDarkRed.setup();
|
||||
// MacDarkRed.setup();
|
||||
MacDarkBlue.setup();
|
||||
try {
|
||||
// UIManager.setLookAndFeel("com.formdev.flatlaf.themes.FlatMacDarkLaf");
|
||||
|
||||
@@ -81,7 +73,7 @@ public class Calculator extends JFrame implements KeyListener {
|
||||
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("/images/appIcon1024.png")));
|
||||
setIconImages(icons);
|
||||
|
||||
setTitle("angel's awesome calculator");
|
||||
setTitle("AAC");
|
||||
setBounds(100, 100, 368, 556);
|
||||
setFocusable(true);
|
||||
addKeyListener(this);
|
||||
@@ -128,7 +120,22 @@ public class Calculator extends JFrame implements KeyListener {
|
||||
);
|
||||
|
||||
buttonPanel.setLayout(new GridLayout(0, 4, 0, 0));
|
||||
|
||||
|
||||
// Menu Bar
|
||||
JMenuBar menubar = new JMenuBar();
|
||||
|
||||
JMenu help = new JMenu("Help");
|
||||
|
||||
JMenuItem about = new JMenuItem("About");
|
||||
about.setMnemonic('A');
|
||||
about.addActionListener(e -> aboutActionPerformed());
|
||||
|
||||
|
||||
help.add(about);
|
||||
help.setMnemonic('H');
|
||||
menubar.add(help);
|
||||
setJMenuBar(menubar);
|
||||
|
||||
modeselect = new JComboBox<>(Modes);
|
||||
modeselect.addActionListener(new ActionListener() {
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -417,8 +424,40 @@ public class Calculator extends JFrame implements KeyListener {
|
||||
contentPane.setLayout(gl_contentPane);
|
||||
|
||||
}
|
||||
|
||||
private void aboutActionPerformed() {
|
||||
JLabel titleLabel = new JLabel( "Angel's Awesome Calculator" );
|
||||
titleLabel.putClientProperty( FlatClientProperties.STYLE_CLASS, "h1" );
|
||||
|
||||
void UpdateMode(String Mode) {
|
||||
String link = "https://git.sillyangel.dev/angel/calc";
|
||||
JLabel linkLabel = new JLabel( "<html><a href=\"#\">" + link + "</a></html>" );
|
||||
linkLabel.setCursor( Cursor.getPredefinedCursor( Cursor.HAND_CURSOR ) );
|
||||
linkLabel.addMouseListener( new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked( MouseEvent e ) {
|
||||
try {
|
||||
Desktop.getDesktop().browse( new URI( link ) );
|
||||
} catch( IOException | URISyntaxException ex ) {
|
||||
JOptionPane.showMessageDialog( linkLabel,
|
||||
"Failed to open '" + link + "' in browser.",
|
||||
"About", JOptionPane.PLAIN_MESSAGE );
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
|
||||
JOptionPane.showMessageDialog( this,
|
||||
new Object[] {
|
||||
titleLabel,
|
||||
"a very okay calculator app created in java (uses flatlaf)",
|
||||
" ",
|
||||
"Copyright " + Year.now() + " angel",
|
||||
linkLabel,
|
||||
},
|
||||
"About", JOptionPane.PLAIN_MESSAGE );
|
||||
}
|
||||
|
||||
private void UpdateMode(String Mode) {
|
||||
if (Mode == "Standard") {
|
||||
System.out.println("User has Selected Standard");
|
||||
} else if (Mode == "Scientific") {
|
||||
@@ -432,7 +471,7 @@ public class Calculator extends JFrame implements KeyListener {
|
||||
}
|
||||
}
|
||||
|
||||
void backspace() {
|
||||
private void backspace() {
|
||||
String tmp = display.getText();
|
||||
if (tmp.length()>1) // if there is more than 1 character
|
||||
display.setText( tmp.substring(0, tmp.length()-1) );
|
||||
@@ -440,12 +479,12 @@ public class Calculator extends JFrame implements KeyListener {
|
||||
display.setText("");
|
||||
}
|
||||
|
||||
void clearEntry() {
|
||||
private void clearEntry() {
|
||||
// Clear only the current display (entry)
|
||||
display.setText("");
|
||||
}
|
||||
|
||||
void clearAll() {
|
||||
private void clearAll() {
|
||||
// Clear everything including operands and operator
|
||||
display.setText("");
|
||||
operand1 = "";
|
||||
@@ -454,7 +493,7 @@ public class Calculator extends JFrame implements KeyListener {
|
||||
resultVisible = false;
|
||||
}
|
||||
|
||||
void reciprocal() {
|
||||
private void reciprocal() {
|
||||
String tmp = display.getText();
|
||||
if (tmp == null || tmp.isEmpty()) return;
|
||||
double value = Double.parseDouble(tmp);
|
||||
@@ -465,7 +504,7 @@ public class Calculator extends JFrame implements KeyListener {
|
||||
}
|
||||
}
|
||||
|
||||
void square() {
|
||||
private void square() {
|
||||
String tmp = display.getText();
|
||||
if (tmp == null || tmp.isEmpty()) return;
|
||||
double value = Double.parseDouble(tmp);
|
||||
@@ -474,7 +513,7 @@ public class Calculator extends JFrame implements KeyListener {
|
||||
resultVisible = true;
|
||||
}
|
||||
|
||||
void squareRoot() {
|
||||
private void squareRoot() {
|
||||
String tmp = display.getText();
|
||||
if (tmp == null || tmp.isEmpty()) return;
|
||||
double value = Double.parseDouble(tmp);
|
||||
@@ -485,7 +524,7 @@ public class Calculator extends JFrame implements KeyListener {
|
||||
}
|
||||
}
|
||||
|
||||
void processDigit(String actionCommand) {
|
||||
private void processDigit(String actionCommand) {
|
||||
if (resultVisible == true) {
|
||||
display.setText("");
|
||||
resultVisible = false;
|
||||
@@ -493,13 +532,13 @@ public class Calculator extends JFrame implements KeyListener {
|
||||
display.setText(display.getText() + actionCommand);
|
||||
|
||||
}
|
||||
void setOperator(String daop) {
|
||||
private void setOperator(String daop) {
|
||||
operand1 = display.getText();
|
||||
operator = daop;
|
||||
display.setText("");
|
||||
}
|
||||
|
||||
void math() {
|
||||
private void math() {
|
||||
operand2 = display.getText();
|
||||
double op1 = Double.parseDouble(operand1);
|
||||
double op2 = Double.parseDouble(operand2);
|
||||
|
||||
Reference in New Issue
Block a user