Results 1 to 3 of 3

Thread: counter in java

  1. #1
    Harvey Lavan is offline Member
    Join Date
    Sep 2009
    Posts
    57
    Rep Power
    3

    Default counter in java

    I am learning JAVA programming language and I wanted to generate a counter. In VB and VB.NET in the IDE and there is a Timer control. But I don’t to know in JAVA.I tried following:
    Code:
    import javax.swing.timer
    If you are having any suggestions then reply me. It can helpful to me.

  2. #2
    Join Date
    Sep 2009
    Posts
    68
    Rep Power
    3

    Default

    I suggest you to refer following example, which will give you something idea about the use of this class:
    Code:
    java.lang.Thread
    And here is the code
    Code:
    try {
       Thread.sleep(time in milliseconds);
    }catch(InterruptedException e){
       System.out.System.out.println("Interrupted by another thread");
    }

  3. #3
    Join Date
    Sep 2009
    Posts
    54
    Rep Power
    3

    Default

    Refer following program to Creating a counter in java:it is very helpful for you.
    Code:
    Public class Test {
    
      Public static void hand(String ... args) {
         SwingUtilities.invokeLater(new Runnable() {
            Public void run() { 
               / / final Calendar calendar = Calendar.getInstance ();
               Final DateFormat frm = DateFormat.getTimeInstance(DateFormat.LONG);
    
               Final javax.swing.Timer tm = new javax.swing.Timer(1000, new ActionListener() {
           
                 Public void actionPerformed(ActionEvent event) {
                    long lg = System.currentTimeMillis();
                    / / calendar.setTimeInMillis (lg);
                    / / Date d = calendar.getTime ();
                    / / In case of error, use commented lines instead.
                    Date d = new Date(lg);
                    String out = frm.frm(d);
                    System.out.System.out.println(out);
                 }
               });
               / / Initialize and configure but.
               Final JToggleButton but = new JToggleButton("Start");
               but.addActionListener(new ActionListener() {
     
                 Public void actionPerformed(ActionEvent event) {
                    if (but.isSelected()) { 
                      but.setText("Stop");
                      tm.restart();
                    }
                    else { 
                      but.setText("Start");
                      tm.stop();
                    }
                 }
               });
               / / Initialize and show jfrm.
               JFrame jfrm = new JFrame("Test");
               jfrm.add(but);
               jfrm.setSize(500, 400);
               jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               jfrm.setVisible(true);
            }
         });
      }
    }

Similar Threads

  1. Can’t play Counter-Strike on Windows 7
    By niks54 in forum Gaming Accessories
    Replies: 1
    Last Post: 03-25-2010, 01:15 PM
  2. Adding Counter in Excel
    By EvansMitchell in forum Software Jargons
    Replies: 0
    Last Post: 01-20-2010, 04:15 PM
  3. How to Install a PC on a Kitchen Counter
    By RodríguezBrown in forum Hardware Jargons
    Replies: 0
    Last Post: 12-23-2009, 04:22 PM
  4. Counter-Strike CT-Spawn
    By qaalin in forum Everything Else
    Replies: 0
    Last Post: 06-28-2008, 06:12 PM
  5. Counter-Strike CT-Spawn
    By jordan in forum Everything Else
    Replies: 0
    Last Post: 05-17-2008, 02:07 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48