\
inner class ,anonymos class로 만들기
수정전 코드 (원본)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | import java.awt.*; import java.awt.event.*; public class Play6 extends Frame implements ActionListener{ Panel p1, p2, p3; TextField tf; TextArea ta; Button b1, b2; public Play6(){ super("Adapter 테스트"); p1=new Panel(); p2=new Panel(); p3=new Panel(); tf=new TextField(35); ta=new TextArea(10,35); b1=new Button("Clear"); b2=new Button("Exit"); p1.add(tf); p2.add(ta); p3.add(b1); p3.add(b2); add("North",p1); add("Center",p2); add("South",p3); setBounds(300,200,300,300); setVisible(true); b1.addActionListener(this); b2.addActionListener(this); tf.addKeyListener(new KeyEventHandler(tf, ta)); addWindowListener(new WindowHandler()); } public void actionPerformed(ActionEvent e){ String str=e.getActionCommand(); if(str.equals("Clear")){ ta.setText(""); tf.setText(""); tf.requestFocus(); } else if(str.equals("Exit")){ System.exit(0); } } public static void main(String[] args){ new Play6(); } } //1///////////////////////////////////////// class WindowHandler extends WindowAdapter{ public void windowClosing(WindowEvent e){ System.exit(0); } } class KeyEventHandler extends KeyAdapter{ TextField tf; TextArea ta; public KeyEventHandler(TextField tf, TextArea ta){ this.tf=tf; this.ta=ta; } ////////////////////////////////////////////////////// public void keyTyped(KeyEvent e){ if(e.getKeyChar() == KeyEvent.VK_ENTER){ ta.append(tf.getText()+"\n"); tf.setText(""); } } } | cs |
[JAVA] 자바 체팅 프로그램 V_1/ TCP 방식/로컬에서 Clint 와 server 만들어서 주고 받기 (0) | 2021.04.15 |
---|---|
[JAVA] javax/Swing/check 라디오 만들기 (0) | 2021.04.14 |
[JAVA] awt/frame 새창 띄우기 (0) | 2021.04.14 |
[JAVA]자바 Synchronized 동기화 / 금융거래 필수 (0) | 2021.04.14 |
[JAVA] 자바 static member 호출 방법 /static 정의/설명/주의점/사용하기 (0) | 2021.04.06 |