Agus_Darmawan

update_jam_pada_form

Jun 20th, 2021
645
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public Menu() {
  2.         initComponents();
  3.         labelTanggal.setText(tanggal);
  4.         setJam();
  5.         //setUndecorated(false);
  6.     }
  7.    
  8.     public final void setJam(){
  9.     ActionListener taskPerformer = new ActionListener() {
  10.  
  11.             @Override
  12.             public void actionPerformed(ActionEvent evt) {
  13.                 String nol_jam = "", nol_menit = "",nol_detik = "";
  14.  
  15.                 java.util.Date dateTime = new java.util.Date();
  16.                 int nilai_jam = dateTime.getHours();
  17.                 int nilai_menit = dateTime.getMinutes();
  18.                 int nilai_detik = dateTime.getSeconds();
  19.  
  20.                 if(nilai_jam <= 9) nol_jam= "0";
  21.                 if(nilai_menit <= 9) nol_menit= "0";
  22.                 if(nilai_detik <= 9) nol_detik= "0";
  23.  
  24.                 String jam = nol_jam + Integer.toString(nilai_jam);
  25.                 String menit = nol_menit + Integer.toString(nilai_menit);
  26.                 String detik = nol_detik + Integer.toString(nilai_detik);
  27.  
  28.                 labelJam.setText(jam+":"+menit+":"+detik+"");
  29.             }
  30.         };
  31.         new Timer(1000, taskPerformer).start();
  32.     }
RAW Paste Data