/*
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
public class Main extends JFrame {
public Main() {
setSize(400,200);
setTitle("+,- 키로 폰트 크기 조절");
Container cnt = getContentPane();
cnt.setLayout(new FlowLayout());
JLabel lbl = new JLabel("Love Java");
lbl.setFont(new Font("Arial", Font.PLAIN, 10));
addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) { }
@Override
public void keyPressed(KeyEvent e) {
System.out.println("1");
Font fnt = lbl.getFont();
int size = fnt.getSize();
if(e.getKeyCode() == KeyEvent.VK_EQUALS) {
lbl.setFont(new Font("Arial", Font.PLAIN, size + 5));
}
if(e.getKeyCode() == KeyEvent.VK_MINUS) {
lbl.setFont(new Font("Arial", Font.PLAIN, size - 5));
}
}
@Override
public void keyReleased(KeyEvent e) { }
});
cnt.add(lbl);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
public class Main extends JFrame {
public Main() {
setTitle("클릭 연습 용 응용프로그램");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(350,350);
Container cnt = getContentPane();
cnt.setLayout(null);
cnt.setSize(350,350);
JLabel lbl = new JLabel("C");
lbl.setSize(20,20);
lbl.setLocation(100,100);
cnt.add(lbl);
addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
System.out.println(e.getPoint() + " " + lbl.getLocation());
if(e.getX() - 20 <= lbl.getX() && e.getY() - 40 <= lbl.getY()
&& e.getX() + 20 >= lbl.getX() && e.getY() + 40 >= lbl.getY()) {
System.out.println("1");
lbl.setLocation((int)(Math.random()*200)+100,(int)(Math.random()*200)+100);
setVisible(true);
}
}
@Override
public void mousePressed(MouseEvent e) { }
@Override
public void mouseReleased(MouseEvent e) { }
@Override
public void mouseEntered(MouseEvent e) { }
@Override
public void mouseExited(MouseEvent e) { }
});
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
public class Main extends JFrame {
public Main() {
setTitle("마우스 휠을 굴려 폰트 크기 조...");
setSize(400,200);
Container cnt = getContentPane();
cnt.setLayout(new FlowLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel lbl = new JLabel("Love Java");
lbl.setFont(new Font("Arial", Font.PLAIN, 10));
addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
Font f = lbl.getFont();
int size = f.getSize();
int n = e.getWheelRotation();
if(n < 0) {
lbl.setFont(new Font("Arial", Font.PLAIN, size + 5));
}
if(n > 0) {
lbl.setFont(new Font("Arial", Font.PLAIN, size - 5));
}
setVisible(true);
}
});
cnt.add(lbl);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
class Main extends JFrame {
String text[] = {"0", "1", "2", "3",
"4", "5", "6", "7",
"8", "9", "CE", "계산",
"+", "-", "x", "/"};
public Main() {
setTitle("계산기 프레임");
setSize(300,250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cnt = getContentPane();
cnt.setLayout(new BorderLayout());
String mathex1 = " ";
JPanel pnl1 = new JPanel();
pnl1.setBackground(Color.gray);
pnl1.setLayout(new FlowLayout());
pnl1.add(new JLabel("수식"));
JTextArea mathex = new JTextArea(1,8);
pnl1.add(mathex);
pnl1.add(new JLabel(" 결과"));
JTextArea result = new JTextArea(1,6);
pnl1.add(result);
JPanel pnl2 = new JPanel();
pnl2.setBackground(Color.white);
pnl2.setLayout(new GridLayout(4,4,5,5));
for(int i = 0; i < 16; i++) {
JButton btn = new JButton(text[i]);
if(i < 10) {
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JButton b = (JButton)e.getSource();
String x = mathex.getText() + btn.getText();
mathex.setText(x);
mathex1.concat(btn.getText());
}
});
}
if(i == 10) {
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JButton b = (JButton)e.getSource();
String x = null;
mathex.setText(x);
}
});
}
if(i == 11) {
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JButton b = (JButton)e.getSource();
int x, rear = 0;
System.out.println("1");
System.out.println(mathex1);
}
});
}
if(i > 11) {
btn.setBackground(Color.cyan);
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JButton b = (JButton)e.getSource();
String x = mathex.getText() + btn.getText();
mathex.setText(x);
mathex1.concat(" " + btn.getText()+" ");
}
});
}
pnl2.add(btn);
}
JPanel pnl3 = new JPanel();
pnl3.setBackground(Color.yellow);
pnl3.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
pnl3.add(new JLabel(" 계산 결과"));
pnl3.add(new JTextField(" "));
cnt.add(pnl1, BorderLayout.NORTH);
cnt.add(pnl2, BorderLayout.CENTER);
cnt.add(pnl3, BorderLayout.SOUTH);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}



