자바 아날로그시계만드는법질문
연꽃
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.calendar;
interface timed {
public void tick(timer t);
}class timer extends thread {
private timed target;
private int interval;
public timer(timed t, int i) {
target = t; interval = i;
setdaemon(true);
}
public void run() {
while (true) {
try {
sleep(interval);
target.tick(this);
}
catch(interruptedexception e) {}
finally{
}
}
}
}
public class timertest extends frame {
public timertest() {
setlayout(new gridlayout(2, 3));
add(new clockcanvas(seoul, 16));
add(new clockcanvas(chicago, 1));
add(new clockcanvas(london, 7));
add(new clockcanvas(moscow, 10));
add(new clockcanvas(paris, 8));
add(new clockcanvas(beijing, 15));
}
public static void main(string[] args) {
frame f = new timertest();
f.setsize(450, 300);
f.setbackground(color.gray);
windowdestroyer listener = new windowdestroyer();
f.addwindowlistener(listener);
f.setvisible(true);
}
}class clockcanvas extends canvas implements timed {
public int basex = 10;
public int basey = 10;
public int clockw = 100;
public int clockh = 100;
public int center = basex + clockh/2;
private int seconds = 0;
private string city;
private int offset;
private final int local = 16;public clockcanvas(string c, int off) {
city = c; offset = off;
new timer(this, 1000).start();
setsize(125, 125);
}
public void paint(graphics g) {
g.setcolor(color.white);
g.filloval(basex,basey, clockw, clockh);
double hourangle = 2 * math.pi * (seconds - 3 * 60 * 60) / (12 * 60 * 60);
double minuteangle = 2 * math.pi * (seconds - 15 * 60) / (60 * 60);
double secondangle = 2 * math.pi * (seconds - 15) / 60;
system.out.println(hourangle : + hourangle);
system.out.println(minuteangel : + minuteangle);
system.out.println(secondangle : + secondangle);
g.setcolor(color.black);
g.drawline(center, center, center + (int)(30 * math.cos(hourangle)),
center + (int)(30 * math.sin(hourangle)));
g.drawline(center, center, center + (int)(40 * math.cos(minuteangle)),
center + (int)(40 * math.sin(minuteangle)));
g.setcolor(color.blue);
g.drawline(center, center, center + (int)(45 * math.cos(secondangle)),
center + (int)(45 * math.sin(secondangle)));
g.setcolor(color.black);
g.drawstring(city, basex, basey+clockh+10);
}
public void tick(timer t) {
calendar cal = calendar.getinstance();
seconds = ((cal.get(calendar.hour) - local + offset)* 60 * 60) +
(cal.get(calendar.minute) * 60) + cal.get(calendar.second);
system.out.println(tick 메소드입니다.seconds : + seconds);
system.out.println(offset : + offset);
system.out.println(local : + local);
system.out.println(hour : + cal.get(calendar.hour_of_day ));
system.out.println(calendar.minute * 60 : + (cal.get(calendar.minute) * 60));
system.out.println(calendar.second : + cal.get(calendar.second));
//system.out.println(gettime : + calendar.gettime() );
repaint();
}
}
class windowdestroyer extends windowadapter {
public void windowclosing(windowevent e) {
system.exit(0);
}
}
자바 책을보며 아날로그시계만들기를했습니다.
근데 thread,callserially,runnable 이세가지를 각각이용해서 아날로그시계를만들수있다고하더라구요...
어떻게만드는지 알고싶습니다. 자바책에는안나오더군요
| 번호 | 제 목 | 글쓴이 | 날짜 |
|---|---|---|---|
| 2752135 | [질문]칼라피커 콘트롤에 특정칼라를 선택된상태로만들려면 어떻게하면되나여? | 널위해 | 2026-10-21 |
| 2752110 | $box.find("img").width()에서 이미지에.. | 해뜰참 | 2026-10-21 |
| 2752024 | 소숫점 뺄셈 !! ㅠㅜ | 초롬 | 2026-10-20 |
| 2751970 | 자바 게임 만들려는데 부탁드립니다 (1) | 라온제나 | 2026-10-19 |
| 2751908 | 자바스크립트 처리속도를 체크할 수 있는 방법 있나요? (1) | 테이 | 2026-10-19 |
| 2751822 | 그누보드 아이프레임으로 구현했는데 제목 클릭해서 들어가면 푸터가 동동...떠다녀요 | 내꺼하자 | 2026-10-18 |
| 2751790 | 자바 그래픽 관련을 공부하고 싶은데요.. 어디 좋은 사이트나 책 없을까요?? (1) | 큰재 | 2026-10-18 |
| 2751733 | CTF가머죠? (5) | 두동 | 2026-10-17 |
| 2751709 | 배열부분 궁금한 부분이있습니다. | 딸기우유 | 2026-10-17 |
| 2751677 | 포인터 책을 보다가,,, (2) | 동백 | 2026-10-17 |
| 2751648 | 익스플로 버전에 따라서 생기는 공백.. (1) | 모아 | 2026-10-17 |
| 2751623 | DEL 태그의에서 선굵기 및 컬러지정이 가능한가 해서요~ (4) | 비치나 | 2026-10-16 |
| 2751573 | 테마 업로드 에러.. (1) | 꽃 | 2026-10-16 |
| 2751548 | 수학? 물리?? (3) | 찬늘 | 2026-10-16 |
| 2751461 | 상단네비 fixed ie6 핵 해결방안이 있을까요? | 맑다 | 2026-10-15 |
| 2751436 | 레이아웃을 잡고 코딩을 하는데 드림위버에서의 결과와 IE에서 결과가 다르게 나오네요. (3) | 키클 | 2026-10-15 |
| 2751403 | 형들좀도와주세요string compression (1) | 알렉산더 | 2026-10-14 |
| 2751349 | 링크 다운로드하기 | 팬지 | 2026-10-14 |
| 2751267 | 플래시8 사용에서 플레이어 만들었는데요 (1) | 블1랙캣 | 2026-10-13 |
| 2751182 | 회원가입 | 파랑새 | 2026-10-12 |
