±Û¾´ÀÌ :À̽¹è 1998³â 2¿ù 02ÀÏ 18:49:59
°£´ÜÇÑ °è»ê±â¸¦ ¸¸µå´Âµ¥ ³Ê¹« ÈûÀÌ µå³×¿ä.
ÀÏ´Ü ¸Ç ¾Æ·¡ Áú¹®ºÎÅÍ ÀоîÁÖ½Ã°í ´äº¯À» ÁÖ½Ã¸é °¨»çÇÏ°Ú½À´Ï´Ù.
//°è»ê±â ÇÁ·Î±×·¥. import java.awt.*; public class Calgui extends Frame { Label digitLabel; String save_value = ""; int second; public Calgui() { resize(200, 250); //¸Þ´º¹Ù ¸¸µé°í ¾ÆÀÌÅÛ ¸¸µé±â. MenuBar FMenuBar = new MenuBar(); setMenuBar(FMenuBar); Menu FileMenu = new Menu("File"); FMenuBar.add(FileMenu); MenuItem ExitItem = new MenuItem("Exit"); FileMenu.add(ExitItem); //¼ýÀÚ°¡ ³ª¿Ã ·¹ÀÌºí ¸¸µé±â. BorderLayout digitLayout = new BorderLayout(); setLayout(digitLayout); digitLabel = new Label("0.", Label.RIGHT); add("North", digitLabel); //ÆdzÚÀ» ¸¸µé°í ¹öÆ° ±¸¼º. Panel digitPanel = new Panel(); digitPanel.setLayout(new GridLayout(0, 4, 5, 5)); digitPanel.add(new Button("7")); digitPanel.add(new Button("8")); digitPanel.add(new Button("9")); digitPanel.add(new Button("/")); digitPanel.add(new Button("4")); digitPanel.add(new Button("5")); digitPanel.add(new Button("6")); digitPanel.add(new Button("*")); digitPanel.add(new Button("1")); digitPanel.add(new Button("2")); digitPanel.add(new Button("3")); digitPanel.add(new Button("-")); digitPanel.add(new Button("0")); digitPanel.add(new Button("+/-")); digitPanel.add(new Button(".")); digitPanel.add(new Button("+")); digitPanel.add(new Button("=")); digitPanel.add(new Button("C")); digitPanel.add(new Button("CE")); add(digitPanel); show(); } public boolean handleEvent (Event e) { //¹öÆ°ÀÌ ´·ÈÀ»¶§. if(e.id == Event.ACTION_EVENT && e.target instanceof Button) { String Buttonlabel = ((Button)(e.target)).getLabel(); digit_to_label(Buttonlabel); } //¸Þ´º¾ÆÀÌÅÛÀÌ ´·ÈÀ»¶§. if (e.id == Event.ACTION_EVENT && e.target instanceof MenuItem) if (((MenuItem)e.target).getLabel().equals("Exit")) System.exit(0); if (e.id == Event.WINDOW_DESTROY) System.exit(0); return false; } //¹öÆ°ÀÌ ´·ÈÀ»¶§ ó¸®. void digit_to_label(String Buttonlabel) { int first_value = 0; int int_value = 0; String symbol_value = ""; try{ int_value = Integer.parseInt(Buttonlabel); } //¼ýÀÚ·Î º¯È¯À» ½ÃÅ°Áö ¸øÇÒ °æ¿ì ¿¹¿Ü»óȲ ¹ß»ý. catch ( NumberFormatException e ) { if (Buttonlabel == "+") symbol_value = "+"; if (Buttonlabel == "=") if (symbol_value == "+") digitLabel.setText(String.valueOf(first_value + second).toString()); } //µé¾î¿Â °ªÀÌ ¼ýÀÚÀ϶§. if (int_value >= 0 && int_value <= 9) //ÀÌ°Ô ¿Ö ½ÇÇàµÇ´ÂÁö.. { save_value = save_value + Buttonlabel; digitLabel.setText(save_value); first_value = int_value; } } public static void main(String args[]) { new Calgui(); } }ÀÌ·¸°Ô ÇÁ·Î±×·¥À» ®´Âµ¥¿ä.