티스토리 뷰


//Label을 상속받는 깜박임레이블 클래스를 정의한다.

class FlickeringLabel extends Label implements Runnable {

public FlickeringLabel(String str) {

super(str);


// 스레드 생성 및 시작

Thread thread = new Thread(this);

thread.start();

}


@Override

public void run() {

// TODO Auto-generated method stub

int n = 0;

while (true) {

if (n == 0)

setBackground(Color.YELLOW);

else

setBackground(Color.GREEN);

if (n == 0)

n = 1;

else

n = 0;

try {

Thread.sleep(100);

} catch (InterruptedException e) {

return;

}

}

}

}


class FlickeringLabelEx extends Frame {

public FlickeringLabelEx() {

setTitle("Flickering Label Ex");


FlickeringLabel fl1 = new FlickeringLabel("껌뻑");

Label fl2 = new Label("안 껌뻑");

FlickeringLabel fl3 = new FlickeringLabel("또 껌뻑");

// 깜박이는 레이블과 정상적인 레이블 생성


Panel p = new Panel();// 패널 생서하고..

p.add(fl1); // 패널에 레이블 붙임

p.add(fl2);

p.add(fl3);

add(p); // 프레임에 패널을 붙임

setSize(300, 100);

setVisible(true);

}

}


public class FlickeringLabelMain {


public static void main(String[] args) {

// TODO Auto-generated method stub

new FlickeringLabelEx();

}

}





'java,web study > 3주차 (7월 15일 ~21일)' 카테고리의 다른 글

텍스트필드 컴포넌트  (0) 2013.07.17
리스트 컴포넌트  (0) 2013.07.17
Label  (0) 2013.07.17
제네릭  (0) 2013.07.16
빠른 열거  (0) 2013.07.16
댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
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
글 보관함