package Calculator;
import javax.swing.*;
import java.awt.*;
public class Calculator extends JFrame {
private JTextField inputSpace;
Calculator(){
setLayout(null);
inputSpace = new JTextField();
inputSpace.setEditable(false);
inputSpace.setBackground(Color.darkGray);
inputSpace.setHorizontalAlignment(JTextField.RIGHT);
inputSpace.setFont(new Font("ITALIC",Font.BOLD,50));
inputSpace.setBounds(0,0,300,100);
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(4,4,2,2));
buttonPanel.setBounds(0,100,300,280);
String[] buttonOrder ={"AC","/","x","=","7","8","9","+","4","5","6","-","1","2","3","0"};
JButton[] buttons = new JButton[buttonOrder.length];
for(int i=0; i<buttonOrder.length; i++){
buttons[i] = new JButton(buttonOrder[i]);
buttons[i].setFont(new Font("ITALIC",Font.BOLD,25));
if(buttonOrder[i] == "AC"){
buttons[i].setBackground(new Color(0xFF9300));buttons[i].setOpaque(true);}
else if((i >= 4 && i <= 6) || (i >= 8 && i <= 10) ||(i>=12 && i<=14)){
buttons[i].setBackground(Color.black);buttons[i].setOpaque(true);}
else {
buttons[i].setBackground(Color.gray);buttons[i].setOpaque(true);}
buttons[i].setForeground(Color.white);buttons[i].setOpaque(true);
buttons[i].setBorderPainted(false);buttons[i].setOpaque(true);
buttonPanel.add(buttons[i]);
}
add(inputSpace);
add(buttonPanel);
add(inputSpace);
setTitle("계산기");
setVisible(true);
setSize(300,400);
setLocationRelativeTo(null);
setResizable(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new Calculator();
}
}