ÇÁ·Î±×·¡¹Ö

 3198, 1/160 ȸ¿ø°¡ÀÔ  ·Î±×ÀΠ 
   ksbgenius
   [ÀÚ¹Ù]°è»ê±â ÇÁ·Î±×·¥

http://www.hackerschool.org/HS_Boards/zboard.php?AllArticle=true&no=3033 [º¹»ç]


import java.awt.event.*;

import javax.swing.*;


class CalculatorTest extends JFrame{
        private JButton button1, button2,button3,button4,button5;
        private JButton button6,button7,button8,button9,button10;
        private JButton button11,button12,button13,button14,button15;
        private JTextField t,t1;
        public CalculatorTest(){
                this.setSize(500,500);
                this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                this.setTitle("°è»ê±â");
                JPanel panel = new JPanel();
                JLabel label = new JLabel("°á°ú = ");
                t = new JTextField(40);
                t1 = new JTextField(30);
                button1 = new JButton("C");
                button2 = new JButton("1");
                button3 = new JButton("2");
                button4 = new JButton("3");
                button5 = new JButton("4");
                button6 = new JButton("5");
                button7 = new JButton("6");
                button8 = new JButton("7");
                button9 = new JButton("8");
                button10 = new JButton("9");
                button11 = new JButton("0");
                button12 = new JButton("+");
                button13 = new JButton("-");
                button14 = new JButton("/");
                button15 = new JButton("*");
                
                button1.addActionListener(new MyListener());
                button2.addActionListener(new MyListener());
                button3.addActionListener(new MyListener());
                button4.addActionListener(new MyListener());
                button5.addActionListener(new MyListener());
                button6.addActionListener(new MyListener());
                button7.addActionListener(new MyListener());
                button8.addActionListener(new MyListener());
                button9.addActionListener(new MyListener());
                button10.addActionListener(new MyListener());
                button11.addActionListener(new MyListener());
                button12.addActionListener(new MyListener());
                button13.addActionListener(new MyListener());
                button14.addActionListener(new MyListener());
                button15.addActionListener(new MyListener());
                
                panel.add(button1);
                panel.add(button2);
                panel.add(button3);
                panel.add(button4);
                panel.add(button5);
                panel.add(button6);
                panel.add(button7);
                panel.add(button8);
                panel.add(button9);
                panel.add(button10);
                panel.add(button11);
                panel.add(button12);
                panel.add(button13);
                panel.add(button14);
                panel.add(button15);
        
        
                panel.add(t);
                panel.add(label);
                panel.add(t1);
                
                
                this.add(panel);
                this.setVisible(true);
        }
        private class MyListener implements ActionListener{
                public void actionPerformed(ActionEvent e){
                        if(e.getSource() == button1){
                                t.setText("Ãë¼Ò");
                        }
                        else if(e.getSource() == button2){
                                t.setText("1");
                        }
                        else if(e.getSource() == button3){
                                t.setText("2");
                        }
                        else if(e.getSource() == button4){
                                t.setText("3");
                        }
                        else if(e.getSource() == button5){
                                t.setText("4");
                        }
                        if(e.getSource() == button6){
                                t.setText("5");
                        }
                        if(e.getSource() == button7){
                                t.setText("6");
                        }
                        if(e.getSource() == button8){
                                t.setText("7");
                        }
                        if(e.getSource() == button9){
                                t.setText("8");
                        }
                        if(e.getSource() == button10){
                                t.setText("9");
                        }
                        if(e.getSource() == button11){
                                t.setText("0");
                        }
                        if(e.getSource() == button12){
                                t.setText("+");
                        }
                        if(e.getSource() == button13){
                                t.setText("-");
                        }
                        if(e.getSource() == button14){
                                t.setText("/");
                        }
                        if(e.getSource() == button15){
                                t.setText("*");
                        }
                        
                        
                
                        
                }
        }
}
public class Calculator{
        public static void main(String[] args){
                CalculatorTest c = new CalculatorTest();
        }
}
        
        

ÀÌ ¼Ò½ºÃ³·³ ´ëÃæ °è»ê±â ÇÁ·Î±×·¥Àº ¸¸µé¾ú´Âµ¥
¹®Á¦Á¡Àº....
¸¸¾à¿¡ ¼ýÀÚ 1À» ÀÔ·ÂÇÑ µÚ¿¡ ´Ù½Ã ¼ýÀÚ 2¸¦ ´©¸£¸é
12 ÀÌ·± ½ÄÀ¸·Î ³ª¿Í¾ß µÇ´Âµ¥ ±×·¸Áö ¾Ê°í
1À» ÀÔ·ÂÇϰí 2¸¦ ´©¸£¸é ±×³É 2¸¸ ³ª¿É´Ï´Ù.
¾î¶»°Ô ÇØ¾ß µÉÁö ±Ã±ÝÇÕ´Ï´Ù...

  Hit : 18019     Date : 2011/06/02 03:16



    
$Zero import java.awt.event.*;

import javax.swing.*;


class CalculatorTest extends JFrame{
private JButton button1, button2,button3,button4,button5;
private JButton button6,button7,button8,button9,button10;
private JButton button11,button12,button13,button14,button15;
private JTextField t,t1;
private String operator = new String("");
private int save = 0;
public CalculatorTest(){
this.setSize(500,500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("°è»ê±â");
JPanel panel = new JPanel();
JLabel label = new JLabel("°á°ú = ");
t = new JTextField(40);
t1 = new JTextField(30);
button1 = new JButton("C");
button2 = new JButton("1");
button3 = new JButton("2");
button4 = new JButton("3");
button5 = new JButton("4");
button6 = new JButton("5");
button7 = new JButton("6");
button8 = new JButton("7");
button9 = new JButton("8");
button10 = new JButton("9");
button11 = new JButton("0");
button12 = new JButton("+");
button13 = new JButton("-");
button14 = new JButton("/");
button15 = new JButton("*");

button1.addActionListener(new MyListener());
button2.addActionListener(new MyListener());
button3.addActionListener(new MyListener());
button4.addActionListener(new MyListener());
button5.addActionListener(new MyListener());
button6.addActionListener(new MyListener());
button7.addActionListener(new MyListener());
button8.addActionListener(new MyListener());
button9.addActionListener(new MyListener());
button10.addActionListener(new MyListener());
button11.addActionListener(new MyListener());
button12.addActionListener(new MyListener());
button13.addActionListener(new MyListener());
button14.addActionListener(new MyListener());
button15.addActionListener(new MyListener());

panel.add(button1);
panel.add(button2);
panel.add(button3);
panel.add(button4);
panel.add(button5);
panel.add(button6);
panel.add(button7);
panel.add(button8);
panel.add(button9);
panel.add(button10);
panel.add(button11);
panel.add(button12);
panel.add(button13);
panel.add(button14);
panel.add(button15);


panel.add(t);
panel.add(label);
panel.add(t1);


this.add(panel); this.setVisible(true);
}
private class MyListener implements ActionListener{

public void actionPerformed(ActionEvent e){

if(e.getSource() == button1){
t.setText("Ãë¼Ò");
}
else if(e.getSource() == button2){
operator += "1";
t.setText(operator);
}
else if(e.getSource() == button3){
operator += "2";
t.setText(operator);
}
else if(e.getSource() == button4){
operator += "3";
t.setText(operator);
}
else if(e.getSource() == button5){
operator += "4";
t.setText(operator);
}
if(e.getSource() == button6){
operator += "5";
t.setText(operator);
}
if(e.getSource() == button7){
operator += "6";
t.setText(operator);
}
if(e.getSource() == button8){
operator += "7";
t.setText(operator);
}
if(e.getSource() == button9){
operator += "8";
t.setText(operator);
}
if(e.getSource() == button10){
operator += "9";
t.setText(operator);
}
if(e.getSource() == button11){
operator += "0";
t.setText(operator);
}
if(e.getSource() == button12){
save = Integer.parseInt(operator);
operator = "";
t.setText("+");
}
if(e.getSource() == button13){
save = Integer.parseInt(operator);
operator = "";
t.setText("-");
}
if(e.getSource() == button14){
save = Integer.parseInt(operator);
operator = "";
t.setText("/");
}
if(e.getSource() == button15){
save = Integer.parseInt(operator);
operator = "";
t.setText("*");
}




}
}
}
public class Calculator{
public static void main(String[] args){
CalculatorTest c = new CalculatorTest();
}
}
Á¦ ³ª¸§´ë·Î ¹Ù²Û ÄÚµåÀÔ´Ï´Ù. Âü°íÇϽñæ. operator º¯¼ö¸¦ ÀÌ¿ëÇØ¼­ ÀԷ¹ÞÀº ¼ýÀÚµéÀ» ¸ðµÎ ÀúÀåÇϱ¸¿ä . ¿¬»êÀÚ¸¦ ÀԷ¹ÞÀ»¶© ÀÔ·Â µÆ´ø ¼ýÀÚ(ÇÇ¿¬»êÀÚ)¸¦ saveº¯¼ö¿¡ ÀúÀåÇØ³õ°í operator¸¦ ´Ù½Ã ÃʱâÈ­ ½Ãŵ´Ï´Ù. ÀÌ·± ¿ø¸®·Î ÇÏ½Ã¸é ½±°Ô ±¸Çö ÇÏ½Ç ¼ö ÀÖÀ»°Å¿¡¿ä . µµ¿òÀÌ µÇ¼Ì±æ.
2011/06/03