Update src/main/java/dev/sillyangel/calc/Calculator.java
Some checks failed
Build the Jar / build (push) Failing after 7s
Some checks failed
Build the Jar / build (push) Failing after 7s
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
package dev.sillyangel.calc;
|
package dev.sillyangel.calc;
|
||||||
|
|
||||||
|
import dev.sillyangel.calc.themes.MacDarkRed;
|
||||||
|
import dev.sillyangel.calc.CalculatorModes;
|
||||||
import java.awt.EventQueue;
|
import java.awt.EventQueue;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import com.formdev.flatlaf.themes.FlatMacDarkLaf;
|
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
@@ -42,13 +43,16 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
private JButton btnPlus;
|
private JButton btnPlus;
|
||||||
protected boolean resultVisible;
|
protected boolean resultVisible;
|
||||||
protected double result;
|
protected double result;
|
||||||
private String[] CalculatorModes = new String[] {"Standard", "Scientific", "Data calculation"};
|
private String[] Modes = 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();
|
// IntelliJTheme.setup(Calculator.class.getResourceAsStream("/DarkPurple.theme.json"));
|
||||||
|
// FlatMacDarkLaf.setup();
|
||||||
|
MacDarkRed.setup();
|
||||||
try {
|
try {
|
||||||
UIManager.setLookAndFeel("com.formdev.flatlaf.themes.FlatMacDarkLaf");
|
// UIManager.setLookAndFeel("com.formdev.flatlaf.themes.FlatMacDarkLaf");
|
||||||
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -125,10 +129,11 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
|
|
||||||
buttonPanel.setLayout(new GridLayout(0, 4, 0, 0));
|
buttonPanel.setLayout(new GridLayout(0, 4, 0, 0));
|
||||||
|
|
||||||
modeselect = new JComboBox<>(CalculatorModes);
|
modeselect = new JComboBox<>(Modes);
|
||||||
modeselect.addActionListener(new ActionListener() {
|
modeselect.addActionListener(new ActionListener() {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
JComboBox cb = (JComboBox)e.getSource();
|
JComboBox<String> cb = (JComboBox<String>)e.getSource();
|
||||||
String Mode = (String)cb.getSelectedItem();
|
String Mode = (String)cb.getSelectedItem();
|
||||||
UpdateMode(Mode);
|
UpdateMode(Mode);
|
||||||
}
|
}
|
||||||
@@ -141,7 +146,9 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
JLabel lblNewLabel = new JLabel("New label");
|
JLabel lblNewLabel = new JLabel("New label");
|
||||||
lblNewLabel.setFocusable(false);
|
lblNewLabel.setFocusable(false);
|
||||||
|
|
||||||
|
btnNewButton_1.setVisible(false);
|
||||||
|
lblNewLabel.setVisible(false);
|
||||||
|
|
||||||
panel.add(modeselect);
|
panel.add(modeselect);
|
||||||
panel.add(lblNewLabel);
|
panel.add(lblNewLabel);
|
||||||
panel.add(btnNewButton_1);
|
panel.add(btnNewButton_1);
|
||||||
@@ -356,7 +363,7 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
btnSquare.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));
|
btnSquareRoot.setFont(new Font("Segoe UI", Font.PLAIN, 29));
|
||||||
|
|
||||||
// Make all buttons non-focusable so keyboard input always goes to the frame
|
// Make all buttons non-focusable so keyboard input always goes to the frame because if we don't it breaks
|
||||||
btnBackspace.setFocusable(false);
|
btnBackspace.setFocusable(false);
|
||||||
btnClear.setFocusable(false);
|
btnClear.setFocusable(false);
|
||||||
btnClearEntry.setFocusable(false);
|
btnClearEntry.setFocusable(false);
|
||||||
@@ -415,9 +422,13 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
if (Mode == "Standard") {
|
if (Mode == "Standard") {
|
||||||
System.out.println("User has Selected Standard");
|
System.out.println("User has Selected Standard");
|
||||||
} else if (Mode == "Scientific") {
|
} else if (Mode == "Scientific") {
|
||||||
System.out.println("User has Selected Scientific Calculator");
|
// System.out.println("User has Selected Scientific Calculator");
|
||||||
} else if (Mode == "Date calculation") {
|
CalculatorModes.Scientific();
|
||||||
System.out.println("User has Selected Date calculation mode");
|
} else if (Mode == "Data calculation") {
|
||||||
|
// System.out.println("User has Selected Date calculation mode");
|
||||||
|
CalculatorModes.DateCalculation();
|
||||||
|
} else {
|
||||||
|
System.out.println(Mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -479,27 +490,6 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
display.setText("");
|
display.setText("");
|
||||||
resultVisible = false;
|
resultVisible = false;
|
||||||
}
|
}
|
||||||
// if (actionCommand == "+") {
|
|
||||||
// btnDiv.setForeground(new Color(0, 0, 0));
|
|
||||||
// btnMul.setForeground(new Color(0, 0, 0));
|
|
||||||
// btnPlus.setForeground(new Color(30, 144, 255));
|
|
||||||
// btnMin.setForeground(new Color(0, 0, 0));
|
|
||||||
// } else if (actionCommand == "*") {
|
|
||||||
// btnDiv.setForeground(new Color(0, 0, 0));
|
|
||||||
// btnMul.setForeground(new Color(30, 144, 255));
|
|
||||||
// btnPlus.setForeground(new Color(0, 0, 0));
|
|
||||||
// btnMin.setForeground(new Color(0, 0, 0));
|
|
||||||
// } else if (actionCommand == "/") {
|
|
||||||
// btnDiv.setForeground(new Color(30, 144, 255));
|
|
||||||
// btnMul.setForeground(new Color(0, 0, 0));
|
|
||||||
// btnPlus.setForeground(new Color(0, 0, 0));
|
|
||||||
// btnMin.setForeground(new Color(0, 0, 0));
|
|
||||||
// } else if (actionCommand == "-") {
|
|
||||||
// btnDiv.setForeground(new Color(0, 0, 0));
|
|
||||||
// btnMul.setForeground(new Color(0, 0, 0));
|
|
||||||
// btnPlus.setForeground(new Color(0, 0, 0));
|
|
||||||
// btnMin.setForeground(new Color(30, 144, 255));
|
|
||||||
// }
|
|
||||||
display.setText(display.getText() + actionCommand);
|
display.setText(display.getText() + actionCommand);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -534,11 +524,6 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
operand1 = "";
|
operand1 = "";
|
||||||
operand2 = "";
|
operand2 = "";
|
||||||
|
|
||||||
// btnDiv.setForeground(new Color(0, 0, 0));
|
|
||||||
// btnMul.setForeground(new Color(0, 0, 0));
|
|
||||||
// btnPlus.setForeground(new Color(0, 0, 0));
|
|
||||||
// btnMin.setForeground(new Color(0, 0, 0));
|
|
||||||
|
|
||||||
resultVisible = true;
|
resultVisible = true;
|
||||||
display.setText(""+result);
|
display.setText(""+result);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user