Page 3 of 3 FirstFirst 123
Results 41 to 59 of 59
  1. #41
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,565
    Rep Power
    25

  2. #42
    acash229 is offline Member
    Join Date
    Sep 2010
    Posts
    60
    Rep Power
    0

    Default

    use it how?

    What do you mean???
    I dont understand what your saying because your sayiing it in part.
    This lab is due in couple of hours. I really need to just finish this one little part. Please can you slack me some break this time. I have been under alot of stress. I am almost done. This timer part is the reall part that is bothering me alot. If i can get the code I can learn from it and next time ill now how to do it.
    Wish you can help :'(

    Thanks

  3. #43
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,565
    Rep Power
    25

    Default

    Here is an example of how you are using n to detect if there have been 3 button clicks:
    if(n>=3){

    How would you use the same type of logic to detect 0 button clicks?

  4. #44
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    OP, no one is going to write this code for you, and asking for it is against forum rules. If you have any specific questions, then please ask and we'll be happy to help you gain an understanding of Java, but just don't ask us to do this for you. Thank you for your cooperation.

  5. #45
    acash229 is offline Member
    Join Date
    Sep 2010
    Posts
    60
    Rep Power
    0

    Default

    What does that have anything to do with the timer??

  6. #46
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,565
    Rep Power
    25

    Default

    You said: The timing should start right when the user clicks the grid button.
    What is the value of n when the user clicks the button for the first time?

  7. #47
    acash229 is offline Member
    Join Date
    Sep 2010
    Posts
    60
    Rep Power
    0

    Default

    0 clicks
    ......

  8. #48
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,565
    Rep Power
    25

    Default

    If you'll go back over all the posts on this thread you'll see how and where to save the start time.
    There is no more I can say without repeating what has been said before.

    Good luck.

  9. #49
    acash229 is offline Member
    Join Date
    Sep 2010
    Posts
    60
    Rep Power
    0

    Default

    Can you tell me what codes to put

  10. #50
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    I know you're getting stressed over the due date, but you have to put in a decent effort here. You're not even trying, it seems; as Norm stated, you've been told where things need to be, what needs to be there, and so on. You've just decided that trying to get people to do your work is a better path.

    And, as mentioned:
    Quote Originally Posted by Fubarable View Post
    OP, no one is going to write this code for you, and asking for it is against forum rules. If you have any specific questions, then please ask and we'll be happy to help you gain an understanding of Java, but just don't ask us to do this for you. Thank you for your cooperation.

  11. #51
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    This thread is starting to look less like a question thread and more like a begging thread.

  12. #52
    acash229 is offline Member
    Join Date
    Sep 2010
    Posts
    60
    Rep Power
    0

    Default

    GUYS HELP ME
    I KINDA GOT IT
    BUT THE SECONDS ARE MESSED UP

    Java Code:
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Random;
    
    
    
    public class JumpingPanel extends JFrame{
    
    
        public static final int BUTTON_WIDTH = 45;
        public static final int BUTTON_HEIGHT = 45;
        static int n=0;
    
        private static final Dimension screenSize =
        		Toolkit.getDefaultToolkit().getScreenSize();
    
        private JPanel middle;
        private TargetPanel target;
    
        private static void resizeComponent(Component c) {
    	    Dimension d = c.getSize(null);
                c.setPreferredSize(new Dimension((int)(0.9*d.width), (int)(0.9*d.height)));
        }
    
    
    
        private static class TargetPanel extends JPanel implements ActionListener{
                private JButton theMainButton;
                private Random rand;
                
    
                public void actionPerformed(ActionEvent ae) {
                JButton source = (JButton)ae.getSource();
                float elapsedTimeMillis = 0;
                double elapsedTimesec1;
                
                
    
                
    
                  
          if (source == theMainButton) {
       
          resizeComponent(this);
       
          setLocation(rand.nextInt(screenSize.width-3*BUTTON_WIDTH),
       
          rand.nextInt(screenSize.height-3*BUTTON_HEIGHT));
       
          long start = System.currentTimeMillis(); // get the starting milli-seconds
       
          n++;
       
          if(n>=3){
       
          JOptionPane.showMessageDialog(null, "You Clicked it " +n);
       
          long elapsedTimeSec = System.currentTimeMillis(); // get the stoping milli-seconds,
      
          elapsedTimesec1 =(double)(elapsedTimeSec - start)/100.0; // calculate the lasting time in seconds.
      
          JOptionPane.showMessageDialog(null, "Took you: " + elapsedTimesec1 + " seconds."); // showing the result.
      
          }
    
                    validate();
                    }
    
            }
    
    
    
    
            public TargetPanel() {
                rand = new Random();
                setLayout(new GridLayout(3,3));
    
                for (int r = 0; r < 3; r++) {
                    for (int c = 0; c < 3; c++) {
                        JButton button = new JButton();
                        if (r == 1 && c == 1) {
                            theMainButton = button;
                            theMainButton.addActionListener(this);
    
                        }
                        button.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
                        add(button);
    
                    }
                }
                setMaximumSize(new Dimension(3*BUTTON_WIDTH,3*BUTTON_HEIGHT));
                Border border = BorderFactory.createLineBorder(Color.BLACK, 4);
                setBorder(border);
            }
        }
    
    
        public static void main(String[] args) {
            JumpingPanel frame = new JumpingPanel();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setTitle("The Clicking Game");
            frame.setMinimumSize(screenSize);
    
            frame.middle = (JPanel)frame.getContentPane();
            frame.middle.setLayout(new FlowLayout());
    
            frame.target = new TargetPanel();
            frame.middle.add(frame.target);
    
            frame.setVisible(true);
    	}
    }

  13. #53
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    By "messed up", do you mean the fact that they're 10x higher than they should be?

    Millis should be divided by 1000, not 100. Other than that, looks fine. What exactly is your current issue?

  14. #54
    acash229 is offline Member
    Join Date
    Sep 2010
    Posts
    60
    Rep Power
    0

    Default

    when i divide by 1000 it gives me .92 seconds. the user takes 10 seconds and it will show up as 2 second s. what am i doing wrong ?


    thanks

  15. #55
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,656
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by acash229 View Post
    when i divide by 1000 it gives me .92 seconds. the user takes 10 seconds and it will show up as 2 second s. what am i doing wrong ?


    thanks
    Obviously your 'start' value is incorrect: it should contain the time when the button was clicked for the first time and please don't beg for us doing your code for you; I doubt any of us will do it because we don't want a person like you in the programming field: you should be capable to fix obvious bugs like this one yourself; we don't need code beggars.

    kind regards,

    Jos

  16. #56
    acash229 is offline Member
    Join Date
    Sep 2010
    Posts
    60
    Rep Power
    0

    Default

    were is my start value ?

  17. #57
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,656
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by acash229 View Post
    were is my start value ?
    It's your code so you should know; don't fool us around and don't keep on begging for code anymore.

    Jos

  18. #58
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,565
    Rep Power
    25

    Default

    He gave up on us and got someone to write his code at HEY guYS please help with this java code - Java

  19. #59
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Page 3 of 3 FirstFirst 123

Similar Threads

  1. New to Java need help with a timer
    By kd0jzi in forum New To Java
    Replies: 3
    Last Post: 03-20-2010, 03:20 AM
  2. Java Timer
    By sasi25 in forum Advanced Java
    Replies: 4
    Last Post: 01-30-2010, 09:19 AM
  3. Timer in java
    By manhit45 in forum New To Java
    Replies: 4
    Last Post: 12-14-2009, 02:27 PM
  4. Replies: 0
    Last Post: 04-04-2008, 02:46 PM
  5. Help with timer in java
    By barney in forum Advanced Java
    Replies: 1
    Last Post: 08-01-2007, 10:24 AM

Tags for this Thread

Posting Permissions

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