자바 디지털 시계 이벤트 처리 질문

조회수 906회

Java Thread 기능을 사용하여 디지털 시계를 만들었지만 시계 부분에 마우스를 선택할 때 +시계가 작동 중일 때 멈춤 +정지되면 다시 실행 +동기화 기능 사용 이 기능을 추가하고 싶습니다. 도와주신다면 감사드리겠습니다

        import java.awt.*;
        import javax.swing.*;
        import java.util.Calendar;

        public class Question4 extends JFrame {
            private Calendar c;
            private int hour, min, second;
            private JLabel time;
            public Question4() {
                this.setTitle("ClockEx");
                this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                this.setLocationRelativeTo(getOwner());

                Container ct = getContentPane();

                ct.setLayout(null);

                time = new JLabel();
                time.setFont(new Font("Arial", Font.ITALIC, 80));
                time.setBounds(35, 30, 400, 100);
                ct.add(time);

                Thread t = new Thread(new thread());
                t.start();

                this.setSize(400, 200);
                this.setVisible(true);
            }

            private class thread implements Runnable {
                public void run() {
                    while(true) {
                        c = Calendar.getInstance();
                        hour = c.get(Calendar.HOUR_OF_DAY);
                        min = c.get(Calendar.MINUTE);
                        second = c.get(Calendar.SECOND);
                        String clockText = Integer.toString(hour);
                        clockText = clockText.concat(":");
                        clockText = clockText.concat(Integer.toString(min));
                        clockText = clockText.concat(":");
                        clockText = clockText.concat(Integer.toString(second));

                        time.setText(clockText);
                    }
                }
            }

            public static void main(String[] args) {
                new Question4();
            }
        }
  • (•́ ✖ •̀)
    알 수 없는 사용자

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)