Facebook
From Colossal Owl, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 144
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.      import javax.swing.*;  
  7.     import java.text.*;  
  8.     import java.util.*;
  9. /**
  10.  *
  11.  * @author maxim
  12.  */
  13.  
  14.     public class zad1 implements Runnable{  
  15.         JFrame f;  
  16.         Thread t=null;  
  17.         int hours=0, minutes=0, seconds=0;  
  18.         String timeString = "";  
  19.         JButton b;  
  20.      
  21.         zad1(){  
  22.         f=new JFrame();  
  23.          
  24.         t = new Thread(this);  
  25.             t.start();  
  26.          
  27.         b=new JButton();  
  28.             b.setBounds(100,100,100,50);  
  29.          
  30.         f.add(b);  
  31.         f.setSize(300,400);  
  32.         f.setLayout(null);  
  33.         f.setVisible(true);  
  34.     }  
  35.      
  36.        
  37.      public void run() {  
  38.           try {  
  39.              while (true) {  
  40.      
  41.                 Calendar cal = Calendar.getInstance();  
  42.                 hours = cal.get( Calendar.HOUR_OF_DAY );  
  43.                 if ( hours > 12 ) hours -= 12;  
  44.                 minutes = cal.get( Calendar.MINUTE );  
  45.                 seconds = cal.get( Calendar.SECOND );  
  46.      
  47.                 SimpleDateFormat formatter = new SimpleDateFormat("hh:mm:ss");  
  48.                 Date date = cal.getTime();  
  49.                 timeString = formatter.format( date );  
  50.      
  51.                 printTime();  
  52.      
  53.                 t.sleep( 1000 );  
  54.              }  
  55.           }  
  56.           catch (InterruptedException e) { }  
  57.      }  
  58.      
  59.     public void printTime(){  
  60.     b.setText(timeString);  
  61.     }  
  62.      
  63.      
  64.         public static void main(String[] args) {  
  65.             zad1 zad1 = new zad1();  
  66.              
  67.     }  
  68.  }  
  69.  
  70.