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;
|
||||
|
||||
import dev.sillyangel.calc.themes.MacDarkRed;
|
||||
import dev.sillyangel.calc.CalculatorModes;
|
||||
import java.awt.EventQueue;
|
||||
import javax.swing.JFrame;
|
||||
import com.formdev.flatlaf.themes.FlatMacDarkLaf;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.UIManager;
|
||||
@@ -42,13 +43,16 @@ public class Calculator extends JFrame implements KeyListener {
|
||||
private JButton btnPlus;
|
||||
protected boolean resultVisible;
|
||||
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;
|
||||
|
||||
public static void main(String[] args) {
|
||||
FlatMacDarkLaf.setup();
|
||||
// IntelliJTheme.setup(Calculator.class.getResourceAsStream("/DarkPurple.theme.json"));
|
||||
// FlatMacDarkLaf.setup();
|
||||
MacDarkRed.setup();
|
||||
try {
|
||||
UIManager.setLookAndFeel("com.formdev.flatlaf.themes.FlatMacDarkLaf");
|
||||
// UIManager.setLookAndFeel("com.formdev.flatlaf.themes.FlatMacDarkLaf");
|
||||
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -125,10 +129,11 @@ public class Calculator extends JFrame implements KeyListener {
|
||||
|
||||
buttonPanel.setLayout(new GridLayout(0, 4, 0, 0));
|
||||
|
||||
modeselect = new JComboBox<>(CalculatorModes);
|
||||
modeselect = new JComboBox<>(Modes);
|
||||
modeselect.addActionListener(new ActionListener() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JComboBox cb = (JComboBox)e.getSource();
|
||||
JComboBox<String> cb = (JComboBox<String>)e.getSource();
|
||||
String Mode = (String)cb.getSelectedItem();
|
||||
UpdateMode(Mode);
|
||||
}
|
||||
@@ -141,7 +146,9 @@ public class Calculator extends JFrame implements KeyListener {
|
||||
JLabel lblNewLabel = new JLabel("New label");
|
||||
lblNewLabel.setFocusable(false);
|
||||
|
||||
|
||||
btnNewButton_1.setVisible(false);
|
||||
lblNewLabel.setVisible(false);
|
||||
|
||||
panel.add(modeselect);
|
||||
panel.add(lblNewLabel);
|
||||
panel.add(btnNewButton_1);
|
||||
@@ -356,7 +363,7 @@ public class Calculator extends JFrame implements KeyListener {
|
||||
btnSquare.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);
|
||||
btnClear.setFocusable(false);
|
||||
btnClearEntry.setFocusable(false);
|
||||
@@ -415,9 +422,13 @@ public class Calculator extends JFrame implements KeyListener {
|
||||
if (Mode == "Standard") {
|
||||
System.out.println("User has Selected Standard");
|
||||
} else if (Mode == "Scientific") {
|
||||
System.out.println("User has Selected Scientific Calculator");
|
||||
} else if (Mode == "Date calculation") {
|
||||
System.out.println("User has Selected Date calculation mode");
|
||||
// System.out.println("User has Selected Scientific Calculator");
|
||||
CalculatorModes.Scientific();
|
||||
} 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("");
|
||||
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);
|
||||
|
||||
}
|
||||
@@ -534,11 +524,6 @@ public class Calculator extends JFrame implements KeyListener {
|
||||
operand1 = "";
|
||||
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;
|
||||
display.setText(""+result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user