Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 어노테이션
- 생성자
- 이클립스
- HTML
- 메소드
- JSP
- Android
- OGNL
- Spring
- 에러페이지
- 국제화
- Menu
- 배열
- 클래스
- JavaScript
- Eclips
- 오버로딩
- Graphic
- 메서드
- 안드로이드
- Java
- 기본
- mybatis
- AWT
- 예외처리
- struts2
- 전화걸기
- oracle
- layout
- paint
Archives
- Today
- Total
note
Adapter Ex 본문
package com.adapter; import java.awt.*; import java.awt.event.*; public class AdapterEx extends Frame implements ActionListener{ Panel p1,p2,p3; TextField tf; TextArea ta; Button b1,b2; public AdapterEx(){ 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); //KeyEventHandlers 가 다른 클래스이기 때문에 tf,ta값을 보낸다(?) tf.addKeyListener(new KeyEventHandlers(tf,ta)); addWindowListener(new WindowEventHandlers()); } 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 AdapterEx(); } } //KeyEvent를 처리하는 클래스 class KeyEventHandlers extends KeyAdapter{ TextField tf; TextArea ta; public KeyEventHandlers(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(""); } } } //Window Event를 처리하는 클래스 class WindowEventHandlers extends WindowAdapter{ public void windowClosing(WindowEvent e){ System.exit(0); } }
package com.adapter2; import java.awt.*; import java.awt.event.*; public class AdapterEx extends Frame implements ActionListener{ Panel p1,p2,p3; TextField tf; TextArea ta; Button b1,b2; public AdapterEx(){ super("Adapte 테스트"); 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 KeyEventHandlers()); addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); } 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 AdapterEx(); } class KeyEventHandlers extends KeyAdapter{ public void keyTyped(KeyEvent e){ if(e.getKeyChar()==KeyEvent.VK_ENTER){ ta.append(tf.getText()+"\n"); tf.setText(""); } } } }
package com.adapter3; import java.awt.*; import java.awt.event.*; public class AdapterEx extends Frame implements ActionListener{ Panel p1,p2,p3; TextField tf; TextArea ta; Button b1,b2; public AdapterEx(){ super("Adapte 테스트"); 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); //KeyEvent를 처리하는 익명내부클래스 형태의 이벤트 처리 tf.addKeyListener(new KeyAdapter(){ public void keyTyped(KeyEvent e){ if(e.getKeyChar()==KeyEvent.VK_ENTER){ ta.append(tf.getText()+"\n"); tf.setText(""); } } }); //WindowEvent를 처리하는 익명내부클래스형태의 이벤트처리 addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); } 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 AdapterEx(); } }
'자바 > AWT' 카테고리의 다른 글
Graphic Color (0) | 2011.12.29 |
---|---|
Graphic Font (0) | 2011.12.29 |
Window Event (0) | 2011.12.29 |
Mouse Motion (0) | 2011.12.29 |
Key Event (0) | 2011.12.29 |