TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Saturday, 11 April 2020

Digital Clock In Applet | Digital Clock Using Applet | Digital Clock In Java Applet

                                Digital clock in Applet

Digital clock can be created by using the Calendar and SimpleDateFormat class.The simple example:

Example of Digital clock in Applet:

     import java.applet.*;  
     import java.awt.*;  
     import java.util.*;   
     import java.text.*;  
     public class DigitalClock extends Applet implements Runnable {  
     Thread t = null;  
      int hours=0, minutes=0, seconds=0;  
      String timeString = "";  
      public void init() {  
      setBackground( Color.green);  
       }  
      public void start() {  
         t = new Thread( this );  
        t.start();  
       }  
      public void run() {  
      try {  
         while (true) {  
            Calendar cal = Calendar.getInstance();  
            hours = cal.get( Calendar.HOUR_OF_DAY );  
            if ( hours > 12 ) hours -= 12;  
            minutes = cal.get( Calendar.MINUTE );  
            seconds = cal.get( Calendar.SECOND );  
           SimpleDateFormat formatter = new SimpleDateFormat("hh:mm:ss");  
            Date date = cal.getTime();  
            timeString = formatter.format( date );    
            repaint();  
            t.sleep( 1000 );  // interval given in milliseconds  
         }  
      }  
      catch (Exception e) { }  
      }  
      public void paint( Graphics g ) {  
      g.setColor( Color.blue );  
      g.drawString( timeString, 50, 50 );  
       }  
}  
myapplet.html

       <html>  
       <body>  
       <applet code="DigitalClock.class" width="300" height="300">  
       </applet>  
       </body>  
       </html>  

digital clock applet | digital clock using applet

Fig: Digital Clock 

No comments:

Post a Comment