자꾸 새 창이 떠요...ㅠㅠ
든해
시계 만들어보려고 했는데 잘 안 되네요...ㅠㅠ
아무튼 전 창 하나에 시간이 바뀌길 바라는 건데 아래 소스는 스레드 반복할 때마다 새 창이 뜨네요.
뭐가 문제일까요?
public class ShutDown{
public static void main(String[] args){
clock cl=new clock();
Thread thread = new Thread(cl);
thread.start();
}
}
public class Frame extends JFrame{
public JLabel label;
public Frame(){
setTitle(현재 시간);
setLayout(new FlowLayout());
setBounds(300, 200, 230, 255);
label = new JLabel();
label.setFont(new Font(Serif,Font.BOLD, 20));
add(label);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
public class clock implements Runnable{
public void run(){
while(true){
Calendar cal = Calendar.getInstance();
int a=cal.get(Calendar.AM_PM);
String ampm=0;
if(a==0){
ampm=AM;
}
else{
ampm=PM;
}
String now=ampm+ +cal.get(Calendar.HOUR)+시+ +cal.get(Calendar.MINUTE)+분+ +cal.get(Calendar.SECOND)+초;
Frame fr1=new Frame();
fr1.label.setText(now);
try{
Thread.sleep(1000);
}catch(InterruptedException e){
e.printStackTrace();
}
}
}
}