Guest User

Untitled

a guest
Jun 24th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.70 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.EventQueue;
  3. import java.util.Calendar;
  4.  
  5. import javax.swing.JFrame;
  6. import javax.swing.JPanel;
  7. import javax.swing.SwingUtilities;
  8. import javax.swing.border.EmptyBorder;
  9. import javax.swing.JLabel;
  10. import javax.swing.JButton;
  11. import java.awt.event.ActionListener;
  12. import java.awt.event.ActionEvent;
  13. import java.awt.Font;
  14. import javax.swing.SwingConstants;
  15.  
  16.  
  17. public class ClockUI extends JFrame {
  18.  
  19.     private String time;
  20.     private JPanel contentPane;
  21.     private JLabel ClockLabel;
  22.     private Clock myClock;
  23.     String _hours;
  24.     String _minutes;
  25.     String _seconds;
  26.     private String alarm_tid;
  27.      Calendar myTime = Calendar.getInstance();
  28.  
  29.     int hours = myTime.get(Calendar.HOUR_OF_DAY);
  30.     int minutes = myTime.get(Calendar.MINUTE);
  31.     int seconds = myTime.get(Calendar.SECOND);
  32.  
  33.    
  34.    
  35.  
  36.     /**
  37.      * Launch the application.
  38.      */
  39.     public static void main(String[] args) {
  40.  
  41.         EventQueue.invokeLater(new Runnable() {
  42.             public void run() {
  43.                 try {
  44.                     ClockUI frame = new ClockUI();
  45.                     frame.setVisible(true);
  46.                 } catch (Exception e) {
  47.                     e.printStackTrace();
  48.                 }
  49.             }
  50.         });
  51.     }
  52.  
  53.     /**
  54.      * Create the frame.
  55.      */
  56.     public ClockUI() {
  57.         setTitle("Digital Clock ");
  58.         myClock = new Clock(ClockUI.this);
  59.         myClock.execute();
  60.  
  61.        
  62.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  63.         setBounds(100, 100, 233, 170);
  64.         contentPane = new JPanel();
  65.         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  66.         setContentPane(contentPane);
  67.         contentPane.setLayout(null);
  68.         ClockLabel = new JLabel();
  69.         ClockLabel.setHorizontalAlignment(SwingConstants.CENTER);
  70.         ClockLabel.setFont(new Font("Calibri", Font.PLAIN, 40));
  71.         ClockLabel.setBounds(22, 11, 172, 74);
  72.          contentPane.add(ClockLabel);
  73.            
  74.            JButton Alarm = new JButton("Alarm");
  75.            Alarm.addActionListener(new ActionListener() {
  76.             public void actionPerformed(ActionEvent arg0) {
  77.                
  78.                 myClock = new Clock(ClockUI.this);
  79.                 myClock.execute();
  80.                
  81.            
  82.                
  83.            
  84.             }});
  85.            Alarm.setBounds(60, 96, 89, 23);
  86.            contentPane.add(Alarm);
  87.        
  88.     }
  89.     public void setTime(int hour, int minute, int second){ 
  90.        
  91.        
  92.         _hours=Integer.toString(hour);
  93.          _minutes=Integer.toString(minute);
  94.         _seconds=Integer.toString(second);
  95.          
  96.            if(hour < 10){
  97.                _hours = "0" + _hours;
  98.     }
  99.            if(minute < 10)
  100.            {
  101.                _minutes = "0" + _minutes;
  102.            }
  103.            if(second < 10){
  104.                _seconds = "0" + _seconds;
  105.            }
  106.            
  107.            time = _hours + ":" +   _minutes + ":" + _seconds;
  108.            
  109.            ClockLabel.setText(time);
  110.    
  111. }
  112.     public void invokeAlarm(){
  113.        
  114.         Color d = new Color(1212);
  115.         contentPane.setBackground(d);
  116.  
  117.         }
  118.             }
Add Comment
Please, Sign In to add comment