Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.EventQueue;
- import java.util.Calendar;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.SwingUtilities;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JLabel;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import java.awt.Font;
- import javax.swing.SwingConstants;
- public class ClockUI extends JFrame {
- private String time;
- private JPanel contentPane;
- private JLabel ClockLabel;
- private Clock myClock;
- String _hours;
- String _minutes;
- String _seconds;
- private String alarm_tid;
- Calendar myTime = Calendar.getInstance();
- int hours = myTime.get(Calendar.HOUR_OF_DAY);
- int minutes = myTime.get(Calendar.MINUTE);
- int seconds = myTime.get(Calendar.SECOND);
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- ClockUI frame = new ClockUI();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public ClockUI() {
- setTitle("Digital Clock ");
- myClock = new Clock(ClockUI.this);
- myClock.execute();
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 233, 170);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- ClockLabel = new JLabel();
- ClockLabel.setHorizontalAlignment(SwingConstants.CENTER);
- ClockLabel.setFont(new Font("Calibri", Font.PLAIN, 40));
- ClockLabel.setBounds(22, 11, 172, 74);
- contentPane.add(ClockLabel);
- JButton Alarm = new JButton("Alarm");
- Alarm.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- myClock = new Clock(ClockUI.this);
- myClock.execute();
- }});
- Alarm.setBounds(60, 96, 89, 23);
- contentPane.add(Alarm);
- }
- public void setTime(int hour, int minute, int second){
- _hours=Integer.toString(hour);
- _minutes=Integer.toString(minute);
- _seconds=Integer.toString(second);
- if(hour < 10){
- _hours = "0" + _hours;
- }
- if(minute < 10)
- {
- _minutes = "0" + _minutes;
- }
- if(second < 10){
- _seconds = "0" + _seconds;
- }
- time = _hours + ":" + _minutes + ":" + _seconds;
- ClockLabel.setText(time);
- }
- public void invokeAlarm(){
- Color d = new Color(1212);
- contentPane.setBackground(d);
- }
- }
Add Comment
Please, Sign In to add comment