Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Help on Timer

  1. #1
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help on Timer

    Hey guys, I am new to the forum and am new to scripting. Currently I have a script for a basic timer. My goal is for you guys to help me to implement some more parts to this timer. As of now all it has is start/stop and reset. My goal is to have it also include intervals. So basically have it on a loop so it will hit 30seconds, start over hit 10 seconds and repeat this process for like 10minutes. Is this possible and is it easy enough for one of you guys to tamper with the script and help me understand what I should include to get this.

    PHP Code:
    public class TimerMain {
    //main function instantiates TimerExample object
    public static void main(String[] args){
    TimerExample display = new TimerExample();
    }
    }

    //imports for TimerExample class:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.*;
    import javax.swing.*;
    public class 
    TimerExample extends JFrame implements ActionListener {
    private 
    JPanel container;
    JLabel labelCounter;
    private 
    Timer timer1 = new Timer(250this);
    int w,x,y,1;
    public 
    TimerExample() {
    //set initial delay to 1000 milliseconds
    timer1.setInitialDelay(1150);

    //initialize window
    container = new JPanel();
    this.add(container);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(200,200);
    this.setVisible(true);

    //start timer
    timer1.start();
    }
    /**
    * when timer begins this method draws ovals that increase in size
    * and descend vertically down the window
    */
    public void actionPerformed(ActionEvent e) {
    if (
    100){
    Graphics g container.getGraphics();
    g.drawOval(w,x,y,z);
    w+2;
    x+2;
    y+2;
    z+2;
    }
    else 
    //stop timer (and drawing) when z coordinate is greater than 99
    timer1.stop();
    }

    Last edited by VIPStephan; 04-01-2012 at 06:36 PM. Reason: wrapped code in appropriate BB tags

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,253
    Thanks
    203
    Thanked 2,557 Times in 2,535 Posts
    This is the JavaScript forum. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia!



    It is your responsibility to die() if necessary….. - PHP Manual

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you for explaining. haha I feel so stupid, hopefully i'm not the only that makes this mistake.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,253
    Thanks
    203
    Thanked 2,557 Times in 2,535 Posts
    Quote Originally Posted by saintwolfe View Post
    thank you for explaining. haha I feel so stupid, hopefully i'm not the only that makes this mistake.
    No. If I had a $ for every time I have posted that message, I could afford a good night out! If Javascript was still called Livescript I expect it would not happen.

    I have reported your post and asked a mod to move the thread to the right forum.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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