// import java.awt.*; public class AWTExample extends Frame { MyButton btn; public AWTExample() { setTitle("ÀÚ¹Ù AWT ¿¹Á¦ ÇÁ·Î±×·¥"); setLayout(new FlowLayout()); // ·¹À̾ƿô °ü¸®ÀÚ¸¦ FlowLayoutÀ¸·Î ÁöÁ¤ add(btn=new MyButton("Button")); /* ·¹À̾ƿô °ü¸®ÀÚ°¡ ÁöÁ¤µÇ¸é ÄÁÅ×ÀÌ³Ê ³»ºÎ¿¡ ÇÏÀ§ À©µµ ¿ì¸¦ »ý¼º, ¹èÄ¡ÇÏ´Â °ÍÀº add()¸¦ »ç¿ëÇÑ´Ù. */ add(new Checkbox("Checkbox")); add(new Label("Label")); List list=new List(3, true); /* Ãʱ⿡ È­¸é¿¡ º¸¿©Áö´Â ¾ÆÀÌÅÛ °³¼ö¸¦ ¼ÂÀ¸·Î ÇÏ°í µ¿½Ã¿¡ ¿©·¯ °³¸¦ ¼±ÅÃÇÒ ¼ö ÀÖ´ÂÁö ¿©ºÎ¸¦ ÂüÀ¸·ÎÇÏ¿© ¸®½ºÆ® ¹Ú½º¸¦ »ý¼º */ add(list); list.addItem("List 1"); list.addItem("List 2"); list.addItem("List 3"); list.addItem("List 4"); add(new Scrollbar(Scrollbar.VERTICAL)); // ¼¼·Î·Î µÈ ½ºÅ©·Ñ ¹Ù »ý¼º add(new TextArea("TextArea Example", 3, 8)); // ÃʱⰪÀ¸·Î ½ºÆ®¸µÀÌ "TextArea Example", 3Çà 8Ä­ÀÎ ÅؽºÆ®¹Ú½º »ý¼º add(new TextField("TextField Example", 9)); // ÃʱⰪÀ¸·Î ½ºÆ®¸µÀÌ "TextField Example"ÀÌ°í 9Ä­ÀÎ ÅؽºÆ®ÇÊµå »ý¼º pack(); // ·¹À̾ƿôµÈ ÄÄÆÛ³ÍÆ® À©µµ¿ìµéÀ» Àç¹èÄ¡ÇÑ´Ù. show(); // À©µµ¿ì¸¦ È­¸é¿¡ Ç¥½ÃÇÑ´Ù. } public boolean handleEvent(Event evt) { // °¢ ÇÏÀ§ À©µµ¿ì¿¡¼­ ¹ß»ýÇÏ´Â À̺¥Æ®µéÀ» ¿©±â¿¡¼­ Çڵ鸵ÇÑ´Ù. System.out.println("À̺¥Æ® ¹ß»ý..."); return true; } public static void main(String args[]) { // ÇÁ·Î±×·¥À» ½ÇÇàÇϸé main()ÀÌ È£ÃâµÈ´Ù. new AWTExample(); } } class MyButton extends Button { /* ¹öÆ°ÀÌ ´­·ÁÁö¸é ÇÁ·Î±×·¥À» Á¾·áÇϵµ·Ï ÇÏ´Â Äݹé ÇÔ¼ö¸¦ ³Ö±â À§ÇØ Button Ŭ·¡½º¿¡¼­ MyButton Ŭ·¡½º¸¦ ÆÄ»ý */ MyButton(String s) { super(s); // s¶ó´Â ½ºÆ®¸µÀ» °¡Áø ¹öÆ°À» »ý¼º } public boolean action(Event e, Object arg) { /* ¼­ºê Ŭ·¡½Ì-¹öÆ°ÀÌ ´­·ÁÁö¸é »óÀ§ À©µµ¿ìÀÎ ÇÁ·¹ÀÓÀ¸·ÎºÎÅÍ À̺¥Æ®¸¦ Àü´Þ¹Þ¾Æ¼­ ó¸®ÇÑ´Ù. */ System.out.println(((Button)e.target).getLabel()); /* Event Ŭ·¡½ºÀÇ target Çʵå´Â À̺¥Æ®°¡ ¹ß»ýÇÑ À©µµ¿ì¸¦ °¡¸®Å²´Ù. */ System.exit(0); return true; } }