자바 아날로그시계만드는법질문
연꽃
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 이세가지를 각각이용해서 아날로그시계를만들수있다고하더라구요...
어떻게만드는지 알고싶습니다. 자바책에는안나오더군요
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2700359 | 3.0 ) SimpleButton 상태 강제 변경 (3) | 희선 | 2025-07-04 |
2700304 | ie8 전용핵 문의 (3) | 여자 | 2025-07-03 |
2700281 | 이런경우 어떻게 코딩해야 표준에 따르는건가요? (6) | 늘솜 | 2025-07-03 |
2700230 | 질문이여 ! | 뿡뿡몬 | 2025-07-03 |
2700205 | 액션스크립트책 좀 추천해주세요. (10) | 화이트캣 | 2025-07-02 |
2700173 | 자바 소스인데 어떤게 에러인지..? (1) | 호빵녀 | 2025-07-02 |
2700142 | 하단이 붙어있는 가변 레이아웃구조 질문드립니다. | 이플 | 2025-07-02 |
2700089 | 이미지를 사다리꼴로 비틀게 하는 액션코드가 있나요? (4) | 여름 | 2025-07-01 |
2700033 | 배경에 그라데이션을 넣으려고 하는데요.. (4) | 화이티 | 2025-07-01 |
2700005 | [질문] TextField 객체의 실제 높이 알아오는 방법 ? | 천사의눈물 | 2025-07-01 |
2699978 | FileReferenceList를 이용하여 업로드시 자꾸 실행속도가 느리다는 팝업이... (10) | 데이비드 | 2025-06-30 |
2699944 | 자바스크립트가 많은 사이트는... (6) | 희나리 | 2025-06-30 |
2699918 | 브라우저마다 다른 input과 텍스트 정렬 (3) | 늘봄 | 2025-06-30 |
2699887 | 동적텍스트를 그래픽으로?? (2) | 족장 | 2025-06-30 |
2699862 | scope넣기 (1) | 아인 | 2025-06-29 |
2699835 | exe로 만드는 방법을....알려주세요.. (5) | 방방 | 2025-06-29 |
2699809 | 롤오버할때 백그라운드 이미지로할때 alt설명은 어떻게해야하죠?..ㅠ (4) | 반혈 | 2025-06-29 |
2699757 | 리스트뷰에 있는 내용을 랜덤으로 추출 | 세실 | 2025-06-28 |
2699725 | JMX 질문입니다. (1) | 시나브로 | 2025-06-28 |
2699695 | 으으아으ㅏ으ㅏ 정말미쳐버리겟네요 | 진달래 | 2025-06-28 |