/*
* File : Window.java
*/
public class Window {
public static void main(String[] args) {
// TODO Auto-generated method stub
new WindowBox();
}
}
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
/*
* File : WindowBox
*/
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class WindowBox extends JFrame {
WindowBox() {
JTextField jtfDisplay = new JTextField(35);
JPanel p = new JPanel();
String[] labels = {
"Backspace", "", "", "CE", "C",
"7", "8", "9", "/", "sqrt",
"4", "5", "6", "x", "%",
"1", "2", "3", "-", "1/x",
"0", "+/-", ".", "+", "="
};
JButton[] buttons = new JButton[25];;
p.setLayout(new GridLayout(5, 5, 3, 3));
int index = 0;
for (int rows = 0; rows<5; rows++) {
for(int cols=0; cols<5; cols++) {
buttons[index] = new JButton(labels[index]);
if(cols >= 3) buttons[index].setForeground(Color.RED);
else buttons[index].setBackground(Color.YELLOW);
buttons[index].setForeground(Color.BLUE);
p.add(buttons[index]);
index++;
}
}
add(jtfDisplay, BorderLayout.NORTH);
add(p, BorderLayout.CENTER);
setTitle("계산기");
setSize(500, 400);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}