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
- 이클립스
- 어노테이션
- oracle
- Menu
- Eclips
- 에러페이지
- 전화걸기
- 배열
- OGNL
- Android
- HTML
- layout
- mybatis
- JSP
- Spring
- 메서드
- 메소드
- AWT
- paint
- JavaScript
- 국제화
- 예외처리
- Graphic
- 기본
- 안드로이드
- 생성자
- 오버로딩
- Java
- struts2
- 클래스
Archives
- Today
- Total
note
swing으로 디지털 시계 만들기 본문
package com.clock;//swing으로 디지털 시계만들기(Thread) import java.awt.FlowLayout; import java.awt.Font; import java.util.Calendar; import javax.swing.JFrame; import javax.swing.JLabel; public class DigitalClock extends JFrame implements Runnable{ private Thread thread; private JLabel label; public DigitalClock(){ super("디지털 시계"); setLayout(new FlowLayout()); label = new JLabel(); label.setFont(new Font("Serif",Font.PLAIN, 20)); if(thread == null){ //this의 의미는 Runnable이 구현된 객체를 뜻함(DigitalClock) thread = new Thread(this); thread.start(); } add(label); setBounds(100,100,400,100); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); } public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); new DigitalClock(); } public void run(){ while(true){ Calendar cal = Calendar.getInstance(); String now = cal.get(Calendar.YEAR)+"년"+ (cal.get(Calendar.MONTH)+1)+"월"+ cal.get(Calendar.DATE)+"일"+ cal.get(Calendar.HOUR)+"시"+ cal.get(Calendar.MINUTE)+"분"+ cal.get(Calendar.SECOND)+"초"; label.setText(now); try{ Thread.sleep(1000); }catch(InterruptedException e){ e.printStackTrace(); } } } }
'자바 > 스레드' 카테고리의 다른 글
스레드 동기화 (0) | 2011.12.30 |
---|---|
Thread Priority (0) | 2011.12.30 |
멀티 스레드 (0) | 2011.12.30 |
thread runnable (0) | 2011.12.30 |
스레드 (0) | 2011.12.30 |