Update src/main/java/dev/sillyangel/calc/Calculator.java
All checks were successful
Build the Jar / build (push) Successful in 5s
All checks were successful
Build the Jar / build (push) Successful in 5s
This commit is contained in:
@@ -2,12 +2,14 @@ package dev.sillyangel.calc;
|
||||
|
||||
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;
|
||||
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;
|
||||
@@ -25,7 +27,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.swing.LayoutStyle.ComponentPlacement;
|
||||
import javax.swing.JLabel;
|
||||
import com.formdev.flatlaf.themes.FlatMacDarkLaf;
|
||||
|
||||
public class Calculator extends JFrame implements KeyListener {
|
||||
|
||||
@@ -41,6 +42,8 @@ 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 JComboBox<String> modeselect;
|
||||
|
||||
public static void main(String[] args) {
|
||||
FlatMacDarkLaf.setup();
|
||||
@@ -74,7 +77,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("angel's awesome calculator");
|
||||
setBounds(100, 100, 368, 556);
|
||||
setFocusable(true);
|
||||
addKeyListener(this);
|
||||
@@ -101,23 +104,17 @@ public class Calculator extends JFrame implements KeyListener {
|
||||
GroupLayout gl_contentPane = new GroupLayout(contentPane);
|
||||
gl_contentPane.setHorizontalGroup(
|
||||
gl_contentPane.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(gl_contentPane.createSequentialGroup()
|
||||
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
|
||||
.addGroup(gl_contentPane.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
|
||||
.addComponent(display, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 378, Short.MAX_VALUE)
|
||||
.addComponent(buttonPanel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 378, Short.MAX_VALUE)))
|
||||
.addGroup(gl_contentPane.createSequentialGroup()
|
||||
.addGap(5)
|
||||
.addComponent(panel, GroupLayout.PREFERRED_SIZE, 379, GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(0, 0, Short.MAX_VALUE)))
|
||||
.addComponent(display, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE)
|
||||
.addComponent(buttonPanel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE))
|
||||
.addContainerGap())
|
||||
.addComponent(panel, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 379, Short.MAX_VALUE)
|
||||
);
|
||||
gl_contentPane.setVerticalGroup(
|
||||
gl_contentPane.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(gl_contentPane.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(panel, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(ComponentPlacement.RELATED)
|
||||
.addComponent(display, GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE)
|
||||
@@ -128,12 +125,21 @@ public class Calculator extends JFrame implements KeyListener {
|
||||
|
||||
buttonPanel.setLayout(new GridLayout(0, 4, 0, 0));
|
||||
|
||||
JButton btnNewButton = new JButton("New button");
|
||||
modeselect = new JComboBox<>(CalculatorModes);
|
||||
modeselect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JComboBox cb = (JComboBox)e.getSource();
|
||||
String Mode = (String)cb.getSelectedItem();
|
||||
UpdateMode(Mode);
|
||||
}
|
||||
});
|
||||
modeselect.setEditable(false);
|
||||
|
||||
JButton btnNewButton_1 = new JButton("New button");
|
||||
JLabel lblNewLabel = new JLabel("New label");
|
||||
|
||||
|
||||
panel.add(btnNewButton);
|
||||
panel.add(modeselect);
|
||||
panel.add(lblNewLabel);
|
||||
panel.add(btnNewButton_1);
|
||||
|
||||
@@ -346,6 +352,16 @@ public class Calculator extends JFrame implements KeyListener {
|
||||
|
||||
}
|
||||
|
||||
void UpdateMode(String Mode) {
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
void clear() {
|
||||
String tmp = display.getText();
|
||||
if (tmp.length()>1) // if there is more than 1 character
|
||||
|
||||
Reference in New Issue
Block a user