'Java > AWT' 카테고리의 다른 글
| Graphic paint (0) | 2012.04.13 |
|---|---|
| Graphic paint 사용법 (0) | 2012.04.13 |
| Graphic 이미지 넣기 (0) | 2012.04.13 |
| Graphic 도형 그리기 (0) | 2012.04.13 |
| Graphic Color (0) | 2012.04.13 |
| Graphic paint (0) | 2012.04.13 |
|---|---|
| Graphic paint 사용법 (0) | 2012.04.13 |
| Graphic 이미지 넣기 (0) | 2012.04.13 |
| Graphic 도형 그리기 (0) | 2012.04.13 |
| Graphic Color (0) | 2012.04.13 |
package com.graphic3;
import java.awt.*;
import java.awt.event.*;
public class GraphicsEx3 extends Frame implements MouseMotionListener{
int x=0;
int y=0;
public static void main(String[] args) {
new GraphicsEx3("GraphicsEx3");
}
public GraphicsEx3(String title){
super(title);
addMouseMotionListener(this);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
});
//Frame X Y width height
setBounds(100,100,500,500);
setVisible(true);
}
public void paint(Graphics g){
g.drawString("마우스를 드래그 해보세요", 10, 50);
g.drawString("*", x, y);
}
public void update(Graphics g){
paint(g);
}
public void mouseMoved(MouseEvent me){}
public void mouseDragged(MouseEvent me){
x = me.getX();
y = me.getY();
/*update(Graphics g)를 재정의 하지 않음
paint(Graphics g)호출
update(Graphics g)를 재정의 하면 update 메소드 호출*/
repaint();
}
}
| 예비 (0) | 2012.04.13 |
|---|---|
| Graphic paint 사용법 (0) | 2012.04.13 |
| Graphic 이미지 넣기 (0) | 2012.04.13 |
| Graphic 도형 그리기 (0) | 2012.04.13 |
| Graphic Color (0) | 2012.04.13 |
package com.graphic3;//Graphic paint 사용법
import java.awt.*;
import java.awt.event.*;
import java.awt.event.MouseMotionListener;
public class GraphicsEx2 extends Frame implements MouseMotionListener{
int x= 0;
int y= 0;
public static void main(String[] args) {
new GraphicsEx2("GraphicsEx2");
}
public GraphicsEx2(String title){
super(title);
addMouseMotionListener(this);
//익명내부 클래스 형태의 이벤트 처리
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
});
//Frame
setBounds(100,100,500,500);
setVisible(true);
}
public void paint(Graphics g){
g.drawString("마우스를 움직여보세요.",10,50);
g.drawString("*",x,y);
}
public void mouseMoved(MouseEvent me){
x =me.getX();
y =me.getY();
repaint();//paint (graphic g)를 호출
//paint를 직접 호출할 수 없기때문에 repaint로 호출
}
public void mouseDragged(MouseEvent me){}
}//class| 예비 (0) | 2012.04.13 |
|---|---|
| Graphic paint (0) | 2012.04.13 |
| Graphic 이미지 넣기 (0) | 2012.04.13 |
| Graphic 도형 그리기 (0) | 2012.04.13 |
| Graphic Color (0) | 2012.04.13 |
package com.graphic3;//이미지 넣기
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
public class ImageTest extends Frame{
public ImageTest(){
setSize(520,385);
setVisible(true);
}
public static void main(String[] args) {
new ImageTest();
}
public void paint(Graphics g){
//Image 그리기
Toolkit tool=Toolkit.getDefaultToolkit();
//Toolkit 객체 생성
//지정된 파일로부터 픽셀 데이터를 얻는 이미지를 리턴
Image image=tool.getImage("1.jpg");
g.drawImage(image, 0, 0, 520, 385, this);
//Image 객체, x,y좌표 width height,
//this = ImageObserver(Image가 구축될때, 비동기 갱신 인터페이스)
//이미지가 변환될때 통지되는 객체
}
}
| Graphic paint (0) | 2012.04.13 |
|---|---|
| Graphic paint 사용법 (0) | 2012.04.13 |
| Graphic 도형 그리기 (0) | 2012.04.13 |
| Graphic Color (0) | 2012.04.13 |
| Graphic Font (0) | 2012.04.13 |
package com.graphic3;//Graphics 도형 그리기
import java.awt.*;
import java.awt.event.*;
import java.awt.Frame;
import java.awt.Color;
class GraphicFrame extends Frame{
Color redColor;
//Paint 메서드 오버라이딩
//paint 메소드를 재정의하면 프로그램 구동시 자동으로 호출됨
public void paint(Graphics g){
redColor = new Color(255,0,0);
g.setColor(redColor);
//사각형 x y width height
g.drawRect(10,30,40,40);
//원(타원)
g.fillOval(70,30,40,40);
//꼭지점 좌표
int x[] = new int[]{10,30,50,40,20};
int y[] = new int[]{107,90,107,130,130};
//다각형
g.drawPolygon(x,y,x.length);
//모서리가 둥근 사각형
// x y width height arWidth arcHeight(마지막 2개는 모깍기 정도)
g.drawRoundRect(70,90,40,40,10,10);
//선 시작x 시작y 끝x 끝 y
g.drawLine(150,50,200,100);
g.drawLine(200, 50, 150, 100);
} //문자열 x,y
public GraphicFrame(){
addWindowListener (new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}});
}
}
public class GraphicTest01 {
public static void main(String[] args) {
GraphicFrame f = new GraphicFrame();
f.setSize(270,150);
f.setVisible(true);
}
}| Graphic paint 사용법 (0) | 2012.04.13 |
|---|---|
| Graphic 이미지 넣기 (0) | 2012.04.13 |
| Graphic Color (0) | 2012.04.13 |
| Graphic Font (0) | 2012.04.13 |
| Adapter Ex (0) | 2012.04.13 |
package com.graphic2;//Graphics COLOR
import java.awt.*;
import java.awt.event.*;
import java.awt.Frame;
import java.awt.Color;
class GraphicFrame extends Frame{
Color redColor;
//Paint 메서드 오버라이딩
//paint 메소드를 재정의하면 프로그램 구동시 자동으로 호출됨
public void paint(Graphics g){
redColor = new Color(255,0,0);//빨간색
g.setColor(redColor);
g.drawString("빨간색 글자", 10, 50);
g.setColor(Color.GREEN);
g.drawString("초록색 글자", 10, 80);
g.setColor(Color.YELLOW);
g.drawString("노란색 글자", 10, 110);
} //문자열 x,y
public GraphicFrame(){
addWindowListener (new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}});
}
}
public class GraphicTest01 {
public static void main(String[] args) {
GraphicFrame f = new GraphicFrame();
f.setSize(270,150);
f.setVisible(true);
}
}
| Graphic 이미지 넣기 (0) | 2012.04.13 |
|---|---|
| Graphic 도형 그리기 (0) | 2012.04.13 |
| Graphic Font (0) | 2012.04.13 |
| Adapter Ex (0) | 2012.04.13 |
| Window Event (0) | 2012.04.13 |
package com.graphic;//Graphics Font
import java.awt.*;
import java.awt.event.*;
import java.awt.Frame;
import java.awt.Font;
class GraphicFrame extends Frame{
//Paint 메서드 오버라이딩
//paint 메소드를 재정의하면 프로그램 구동시 자동으로 호출됨
public void paint(Graphics g){
g.drawString("글꼴체가 변경되나유?", 10,60);
Font f = new Font("궁서체",Font.BOLD,20);
g.setFont(f);
g.drawString("ㅎㅎㅎㅎㅎㅎㅎㅎ",10,100);
} //문자열 x,y
public GraphicFrame(){
addWindowListener (new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}});
}
}
public class GraphicTest01 {
public static void main(String[] args) {
GraphicFrame f = new GraphicFrame();
f.setSize(270,150);
f.setVisible(true);
}
}
| Graphic 도형 그리기 (0) | 2012.04.13 |
|---|---|
| Graphic Color (0) | 2012.04.13 |
| Adapter Ex (0) | 2012.04.13 |
| Window Event (0) | 2012.04.13 |
| Mouse Motion (0) | 2012.04.13 |
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();
}
}| Graphic Color (0) | 2012.04.13 |
|---|---|
| Graphic Font (0) | 2012.04.13 |
| Window Event (0) | 2012.04.13 |
| Mouse Motion (0) | 2012.04.13 |
| Key Event (0) | 2012.04.13 |
package com.event;//Window Event
import java.awt.*;
import java.awt.event.*;
public class WindowEventEx extends Frame implements WindowListener{
Label exit;
public WindowEventEx(){
super("WindowEvent 테스트");
exit = new Label("프레임의 종료 버튼을 눌러 주세요");
add(exit);
setBounds(300,300,200,200);
setVisible(true);
addWindowListener(this);
}
public static void main(String[] args){
new WindowEventEx();
}
public void windowClosing(WindowEvent e){
System.exit(0);
}
public void windowActivated(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowOpened(WindowEvent e){}
}
package com.adapter;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
//다중 상속때문에 하나더 클래스 생성
//아답타 클래스를 사용해서 이벤트 처리
class WindowEventHandler extends WindowAdapter{
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
public class WindowEventEx extends Frame{
public WindowEventEx(){
super("이벤트 테스트");
//Frame 이벤트 소스와 WindowAdapter가 상속되어 인벤트를 처리할 수
//있는 객체와 연결
addWindowListener(new WindowEventHandler());
setSize(300,200);
setLocation(100,200);
setVisible(true);
}
public static void main(String[] args) {
new WindowEventEx();
}
}
package com.adapter2;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
//다중 상속때문에 하나더 클래스 생성
//아답타 클래스를 사용해서 이벤트 처리
public class WindowEventEx extends Frame{
public WindowEventEx(){
super("이벤트 테스트");
//Frame 이벤트 소스와 WindowAdapter가 상속되어 인벤트를 처리할 수 있는 객체와 연결
//익명 내부 클래스 형태로 이벤트 처리
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
setSize(300,200);
setLocation(100,200);
setVisible(true);
}
//멤버 내부 클래스 형태
/*class WindowEventHandler extends WindowAdapter{
}*/
public static void main(String[] args) {
new WindowEventEx();
}
}| Graphic Font (0) | 2012.04.13 |
|---|---|
| Adapter Ex (0) | 2012.04.13 |
| Mouse Motion (0) | 2012.04.13 |
| Key Event (0) | 2012.04.13 |
| Iteam Event (0) | 2012.04.13 |
package com.event; //Mouse Motion
import java.awt.Color;
import java.awt.Frame;
import java.awt.Label;
import java.awt.Button;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.event.ActionListener;
public class MouseMotionEx extends Frame implements ActionListener, MouseMotionListener{
Label move = new Label("마우스 따라 다니기", Label.CENTER);
Button exit = new Button("종료");
public MouseMotionEx(){
setTitle("MouseMotion 테스트");
//좌표로 컴포넌트의 위치를 지정할경우 레이아웃을 사용하지 않음
setLayout(null);
move.setBounds(100,50,150,20);//x,y width height
exit.setBounds(250,500,50,30);
move.setForeground(Color.white);
move.setBackground(Color.red);
add(move); //Frame에 Label 등록
add(exit);
//Frame의 x,y width , height
setBounds(300,100,500,600);
setVisible(true);
exit.addActionListener(this);
//Frame 이벤트 소스와 이벤트 리스너가 구현된 객체 연결
addMouseMotionListener(this);
}
public static void main(String[] args) {
new MouseMotionEx();
}
//이벤트 핸들러
public void actionPerformed(ActionEvent e){
System.exit(0);
}
//이벤트 핸들러
public void mouseMoved(MouseEvent e){
Point p = e.getPoint(); //마우스의 포인터의 x,y
move.setLocation(p);
}
//이벤트 핸들러
public void mouseDragged(MouseEvent e){}
}| Adapter Ex (0) | 2012.04.13 |
|---|---|
| Window Event (0) | 2012.04.13 |
| Key Event (0) | 2012.04.13 |
| Iteam Event (0) | 2012.04.13 |
| 이벤트 처리 (0) | 2012.04.13 |
package com.event;//key Event
import java.awt.TextArea;
import java.awt.Frame;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class KeyEventEx extends Frame implements KeyListener{
//이벤트 리스너
//이벤트 소스
TextArea ta = new TextArea();
public KeyEventEx(){
super("KeyEvent 테스트");
add(ta);
setBounds(300,300,300,300);
setVisible(true);
//이벤트 소스와 이벤트 리스너가 구현된 객체 연결
ta.addKeyListener(this);
}
//인터페이스를 구현했기 때문에 사용하지 않더라도 포함되어야됨
public void keyReleased(KeyEvent e){}
public void keyTyped(KeyEvent e){}
public void keyPressed(KeyEvent e){
if(e.getKeyCode()==KeyEvent.VK_DOWN)
ta.append("Down Key\n");
if(e.getKeyCode()==KeyEvent.VK_UP)
ta.append("Up Key\n");
if(e.getKeyCode()==KeyEvent.VK_LEFT)
ta.append("Left Key\n");
if(e.getKeyCode()==KeyEvent.VK_RIGHT)
ta.append("Right Key\n");
if(e.getKeyCode()==KeyEvent.VK_ENTER)
ta.append("Enter Key");
}
public static void main(String[] args){
new KeyEventEx();
}
}| Window Event (0) | 2012.04.13 |
|---|---|
| Mouse Motion (0) | 2012.04.13 |
| Iteam Event (0) | 2012.04.13 |
| 이벤트 처리 (0) | 2012.04.13 |
| AWT 프레임의 배치관리자로 보더 레이아웃 설정하기 (0) | 2012.04.13 |
package com.event;//ItemEvent 살펴보기
import java.awt.Panel;
import java.awt.Button;
import java.awt.Checkbox;
import java.awt.TextArea;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
public class ItemEventEx extends Frame implements ItemListener,ActionListener{
//패널로 감싸서 확대시키지 않음
Panel p1 = new Panel();
Panel p2 = new Panel();
TextArea ta = new TextArea(5,20);
//이벤트 소스
Button exit = new Button("종료");
Checkbox cb1 = new Checkbox("축구",false);
Checkbox cb2 = new Checkbox("야구",false);
Checkbox cb3 = new Checkbox("농구",false);
Checkbox cb4 = new Checkbox("배구",false); //기본적으로 체크를 안시키려면 false
public ItemEventEx(){
super("ItemEvent 테스트");
p1.add(cb1);
p1.add(cb2);
p1.add(cb3);
p1.add(cb4);
p2.add(exit);
add("North",p1);
add("South",p2);
add("Center",ta);
setBounds(300,300,300,300);
setVisible(true);
//이벤트 소스와 이벤트 리스너가 구현된 객체
exit.addActionListener(this);
cb1.addItemListener(this);
cb2.addItemListener(this);
cb3.addItemListener(this);
cb4.addItemListener(this);
}
public static void main(String[] args) {
new ItemEventEx();
}
//ActionEvent를 처리하는 이벤트 핸들러
public void actionPerformed(ActionEvent e){
System.exit(0);
}
//ItemEvent를 처리하는 이벤트 핸들러
public void itemStateChanged(ItemEvent e){
if(e.getStateChange()==ItemEvent.SELECTED)
ta.append(e.getItem() + "을 선택\n\n");
else if(e.getStateChange() == ItemEvent.DESELECTED)
ta.append(e.getItem()+"을 취소\n\n");
}
}
| Mouse Motion (0) | 2012.04.13 |
|---|---|
| Key Event (0) | 2012.04.13 |
| 이벤트 처리 (0) | 2012.04.13 |
| AWT 프레임의 배치관리자로 보더 레이아웃 설정하기 (0) | 2012.04.13 |
| AWT Penel 테스트 (0) | 2012.04.13 |
package com.event;//이벤트 처리 (소스, 핸들러 ,리스너)
import java.awt.Panel;
import java.awt.Button;
import java.awt.TextArea;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.BorderLayout;
public class ActionEventEx extends Frame implements ActionListener{
//이벤트 리스너
/*이벤트 처리순서
1. 이벤트 소스와 이벤트 리스너가 구현된 객체를 연결
2. 이벤트 핸들러를 구현
3.이벤트가 발생하면 연결되어 있는 이벤트 핸들러가 호출
JVM은 이벤트 객체를 생성해서 이벤트 핸들러에 전달됨*/
Panel p;
Button input,exit;
TextArea ta;
public ActionEventEx(){
super("ActionEvent Test");
p=new Panel();
//이벤트 소스
input=new Button("입력");
exit=new Button("종료");
ta = new TextArea();
//이벤트 소스와 이벤트 리스너가 구현된 이벤트 처리 객체와 연결
input.addActionListener(this);
exit.addActionListener(this);
p.add(input);
p.add(exit);
add(p, BorderLayout.NORTH);
add(ta, BorderLayout.CENTER);
setBounds(300,300, 300,200);
setVisible(true);
}
//이벤트 핸들러
//이벤트 소스와 이벤트 리스너가 구현된 객체 연결했기 때문에
//이벤트가 발생하면 자동적으로 이벤트 핸들러 호출됨
public void actionPerformed(ActionEvent ae){
//이벤트 객체
//JVM이 이벤트가 발생하면 이벤트 종류분석해서
//해당 이벤트 정보를 담을 수 있는 객체 생성
String name;
name=ae.getActionCommand();
if(name.equals("입력"))
ta.append("버튼이 입력되었습니다.\n");
else
System.exit(0); //프로그램 정상 종료
}
public static void main(String[] args) {
new ActionEventEx();
}
}
| Key Event (0) | 2012.04.13 |
|---|---|
| Iteam Event (0) | 2012.04.13 |
| AWT 프레임의 배치관리자로 보더 레이아웃 설정하기 (0) | 2012.04.13 |
| AWT Penel 테스트 (0) | 2012.04.13 |
| AWT로 버튼생성 (0) | 2012.04.13 |
package com.display;//프레임의 배치관리자로 보더 레이아웃 설정하기
import java.awt.Frame;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.Panel;
class FrameEx extends Frame{
public FrameEx(){
super("BorderLayout Test");
//보더 레이아웃 (borderLayout)을 배치관리자로 설정 (레이아웃 지정)
//Frame에는 기본적으로 BorderLayout 지정됨
//아래 메소드 생략 가능
setLayout(new BorderLayout());
//컴포넌트를 컨테이너에 추가할때 레이아웃의 위치를 지정
//패널로 감싸면 버튼이 확장되지 않음
Panel p = new Panel();
Button b = new Button("Button 01");
p.add(b); //Panel에 button 등록
//문자열 상수 North를 리턴함
add(p, BorderLayout.NORTH);
add(new Button("Button 02"), "West");
add(new Button("Button 03"), "Center");
add(new Button("Button 04"), "East");
add(new Button("Button 05"), "South");
setSize(300,200);
setVisible(true);
//X버튼 종료처리
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}//WindowClosing 메서드끝
}//클래스 정의끝
); //AaddWindowListener 메서드 끝
}
}
public class FrameTest04{
public static void main(String[] args) {
new FrameEx();
}
}
| Iteam Event (0) | 2012.04.13 |
|---|---|
| 이벤트 처리 (0) | 2012.04.13 |
| AWT Penel 테스트 (0) | 2012.04.13 |
| AWT로 버튼생성 (0) | 2012.04.13 |
| AWT 기본2 (0) | 2012.04.13 |
package com.display;//awt 패널테스트
import java.awt.Frame;
import java.awt.Panel;
import java.awt.Button;
public class PanelTest extends Frame{
public PanelTest(){
super("Panel 테스트");
Panel p = new Panel();
Button b = new Button("확인");
p.add(b); //Panel에 Button등록
add(p); //Frame에 Panel 등록
/*setSize(300,200);
setLocation(100,100);*/
setVisible(true);
setBounds(100,200,300,400);
//x , y , width ,height
}
public static void main(String[] args) {
new PanelTest();
}
}