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 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;
|
||||||
import javax.swing.GroupLayout;
|
import javax.swing.GroupLayout;
|
||||||
import javax.swing.GroupLayout.Alignment;
|
import javax.swing.GroupLayout.Alignment;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
import java.awt.GridLayout;
|
import java.awt.GridLayout;
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
@@ -25,7 +27,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.swing.LayoutStyle.ComponentPlacement;
|
import javax.swing.LayoutStyle.ComponentPlacement;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import com.formdev.flatlaf.themes.FlatMacDarkLaf;
|
|
||||||
|
|
||||||
public class Calculator extends JFrame implements KeyListener {
|
public class Calculator extends JFrame implements KeyListener {
|
||||||
|
|
||||||
@@ -41,6 +42,8 @@ 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 JComboBox<String> modeselect;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
FlatMacDarkLaf.setup();
|
FlatMacDarkLaf.setup();
|
||||||
@@ -74,7 +77,7 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("/images/appIcon1024.png")));
|
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("/images/appIcon1024.png")));
|
||||||
setIconImages(icons);
|
setIconImages(icons);
|
||||||
|
|
||||||
setTitle("angel's awesome calculator)");
|
setTitle("angel's awesome calculator");
|
||||||
setBounds(100, 100, 368, 556);
|
setBounds(100, 100, 368, 556);
|
||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
addKeyListener(this);
|
addKeyListener(this);
|
||||||
@@ -102,38 +105,41 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
gl_contentPane.setHorizontalGroup(
|
gl_contentPane.setHorizontalGroup(
|
||||||
gl_contentPane.createParallelGroup(Alignment.LEADING)
|
gl_contentPane.createParallelGroup(Alignment.LEADING)
|
||||||
.addGroup(gl_contentPane.createSequentialGroup()
|
.addGroup(gl_contentPane.createSequentialGroup()
|
||||||
|
.addContainerGap()
|
||||||
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
|
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
|
||||||
.addGroup(gl_contentPane.createSequentialGroup()
|
.addComponent(display, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE)
|
||||||
.addContainerGap()
|
.addComponent(buttonPanel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE))
|
||||||
.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)))
|
|
||||||
.addContainerGap())
|
.addContainerGap())
|
||||||
|
.addComponent(panel, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 379, Short.MAX_VALUE)
|
||||||
);
|
);
|
||||||
gl_contentPane.setVerticalGroup(
|
gl_contentPane.setVerticalGroup(
|
||||||
gl_contentPane.createParallelGroup(Alignment.LEADING)
|
gl_contentPane.createParallelGroup(Alignment.LEADING)
|
||||||
.addGroup(gl_contentPane.createSequentialGroup()
|
.addGroup(gl_contentPane.createSequentialGroup()
|
||||||
.addContainerGap()
|
|
||||||
.addComponent(panel, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)
|
.addComponent(panel, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)
|
||||||
.addPreferredGap(ComponentPlacement.RELATED)
|
.addPreferredGap(ComponentPlacement.RELATED)
|
||||||
.addComponent(display, GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE)
|
.addComponent(display, GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE)
|
||||||
.addGap(27)
|
.addGap(27)
|
||||||
.addComponent(buttonPanel, GroupLayout.PREFERRED_SIZE, 359, GroupLayout.PREFERRED_SIZE)
|
.addComponent(buttonPanel, GroupLayout.PREFERRED_SIZE, 359, GroupLayout.PREFERRED_SIZE)
|
||||||
.addContainerGap(199, Short.MAX_VALUE))
|
.addContainerGap(199, Short.MAX_VALUE))
|
||||||
);
|
);
|
||||||
|
|
||||||
buttonPanel.setLayout(new GridLayout(0, 4, 0, 0));
|
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");
|
JButton btnNewButton_1 = new JButton("New button");
|
||||||
JLabel lblNewLabel = new JLabel("New label");
|
JLabel lblNewLabel = new JLabel("New label");
|
||||||
|
|
||||||
|
|
||||||
panel.add(btnNewButton);
|
panel.add(modeselect);
|
||||||
panel.add(lblNewLabel);
|
panel.add(lblNewLabel);
|
||||||
panel.add(btnNewButton_1);
|
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() {
|
void clear() {
|
||||||
String tmp = display.getText();
|
String tmp = display.getText();
|
||||||
if (tmp.length()>1) // if there is more than 1 character
|
if (tmp.length()>1) // if there is more than 1 character
|
||||||
|
|||||||
Reference in New Issue
Block a user