Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 22 of 22

Thread: TIMER HELP PLEASE

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default HELP ABOUT [COUNTDOWN] OR [TIMER] using GUI.

    can you help me guys . i have a project and it a microwave . so i need a timer that countdown . can you help me and explain please ?


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: HELP ABOUT [COUNTDOWN] OR [TIMER] using GUI.

    Sorry about that. Post is now separated into its own thread.

    Since you're building a GUI, and I assume it will be Swing, then have you reviewed Oracle's tutorial on javax.swing.Timer? If not, I recommend you review that and create a small app that displays a countdown or something using a timer. Come back with that code when you need help.

  3. #3
    Junior Member
    Join Date
    Sep 2014
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default ABOUT UI SWING AND I THINK ITS NEW . WELL IN OUR SCHOOL ITS NEW ASAP

    guys , i want to ask something about UI swing . well it is about TIMER or COUNTDOWN . well i think everybody knows OVEN right . theres a TIMER or a COUNTDOWN . how will i apply it to my UI swing ? help anyone please . TNX .

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: HELP ABOUT [COUNTDOWN] OR [TIMER] using GUI.

    Threads merged.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: HELP ABOUT [COUNTDOWN] OR [TIMER] using GUI.

    Are you asking about how to build a GUI that changes what it displays over time?
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Sep 2014
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: HELP ABOUT [COUNTDOWN] OR [TIMER] using GUI.

    yeah like this . 00:00:00 then it will countdown

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: HELP ABOUT [COUNTDOWN] OR [TIMER] using GUI.

    What have you tried?
    What problems are you having?
    Do you have any specific java programming questions?
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    Sep 2014
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: HELP ABOUT [COUNTDOWN] OR [TIMER] using GUI.

    never tried anything yet . well i dont know where to start . but this is the only problem now the timer . is there a java code for that like .isDone(); like this ?

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: HELP ABOUT [COUNTDOWN] OR [TIMER] using GUI.

    Break the problem down into two steps:
    1) display the values that are to be changed over time
    Code that and get it working
    When that works, move to:
    2) change the display over time
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Junior Member
    Join Date
    Sep 2014
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: HELP ABOUT [COUNTDOWN] OR [TIMER] using GUI.

    can you explain it basically sir ?

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: HELP ABOUT [COUNTDOWN] OR [TIMER] using GUI.

    Do one step at a time. First:
    1) create a GUI that displays a value
    See the tutorial: Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)
    If you don't understand my answer, don't ignore it, ask a question.

  12. #12
    Junior Member
    Join Date
    Sep 2014
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: HELP ABOUT [COUNTDOWN] OR [TIMER] using GUI.

    DONE ! how about the timer HH:MM:SS

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: HELP ABOUT [COUNTDOWN] OR [TIMER] using GUI.

    Look at the Timer class in the swing package.
    If you don't understand my answer, don't ignore it, ask a question.

  14. #14
    Junior Member
    Join Date
    Sep 2014
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default TIMER HELP PLEASE

    this is my code.
    import java.awt.*;
    import java.util.Date;
     
    import javax.swing.*;
     
    import java.awt.BorderLayout;
     
    import java.awt.Dimension;
    import java.awt.event.*;
     
     
    public class MicroWave extends JFrame implements ActionListener {
     
     
     
    		  JButton n0,n1,n2,n3,n4;
    		  JButton n5,n6,n7,n8,n9;
    		  JButton start,stop;
    		   JPanel keyButtons;
     
    		  JPanel South;
    		  JPanel North;
    		  JPanel West;
    		  JPanel East;
    		  JPanel time;
    		Timer starter;
    		  JTextField screen;
     
    			  long cd = 1800000; 
    			   java.text.SimpleDateFormat tformat = new java.text.SimpleDateFormat("hh:mm:ss");  
    			     JTextField timer = new JTextField(tformat.format(new Date(cd)),JTextField.CENTER);  
     
    			public void actionPerformed(ActionEvent arg0) {
     
    				if(timer.getText().equals("00:00:00"))
    				{
    					timer.setText("");
    					JButton source = (JButton)arg0.getSource();
    					timer.replaceSelection(arg0.getActionCommand());
    				}
    				else{
    					JButton source = (JButton)arg0.getSource();
    					timer.replaceSelection(arg0.getActionCommand());
    				}
     
    				 if(arg0.getSource().equals(start)){
    				 ActionListener al = new ActionListener(){  
    				      long x = cd - 1000;  
    				      public void actionPerformed(ActionEvent ae){ 
     
     
    				    	  timer.setText(tformat.format(new Date(x)));  
    				          x -= 1000;}};  
    				     starter = new Timer(1000, al);
    				     starter.start();  
    				      }if(arg0.getSource().equals(stop)){
    				    	  starter.stop();
    				    	  timer.setText("00:00:00");
    				      }
    			}
     
    		public MicroWave(){
     
     
     
     
     
     
    		n1 = new JButton("1"); 	
    		n2 = new JButton("2"); 
    		n3 = new JButton("3"); 
    		n4 = new JButton("4"); 
    		n5 = new JButton("5"); 
    		n6 = new JButton("6"); 
    		n7 = new JButton("7"); 
    		n8 = new JButton("8"); 
    		n9 = new JButton("9"); 
    		start = new JButton("START"); 
    		n0 = new JButton("0"); 
    		stop = new JButton("STOP"); 
     
    		North= new JPanel(new BorderLayout(260,0));
    		South= new JPanel(new FlowLayout(FlowLayout.RIGHT));
    		West = new JPanel(new FlowLayout(FlowLayout.LEFT));
    		East = new JPanel(new FlowLayout(FlowLayout.RIGHT));
     
     
    		keyButtons = new JPanel();
     
    		time = new JPanel();
    		screen = new JTextField("SCREEN");
     
     
     
     
    		West.add(screen);
    		time.add(timer);
     
    		North.add(time,BorderLayout.EAST);
    		South = new JPanel();
     
    	}
     
    		public void launchFrame(){
     
    			keyButtons.setLayout(new GridLayout(4,3));
    			timer.setText("00:00:00");
    			South.setPreferredSize(new Dimension(100,100));
    			screen.setPreferredSize(new Dimension(440,700));
    			timer.setPreferredSize(new Dimension(227,70));
    			keyButtons.setPreferredSize(new Dimension(235,250));
    			screen.add(new JTextField(8));
    			//INPUT WILL START AT THE CENTER
    			 timer.setHorizontalAlignment(JTextField.CENTER);
    			 screen.setHorizontalAlignment(JTextField.CENTER);
    			 //COLOR FOR JTEXTFIELD BACKGROUND//
    			 timer.setBackground(Color.DARK_GRAY); 
    			 screen.setBackground(Color.DARK_GRAY); 
    			 //FONT COLOR //
    			 screen.setForeground(Color.RED);  
    			 timer.setForeground(Color.RED);
    			 //FONT SIZE//
    				screen.setFont(new Font("Tahoma",1,55));
    				timer.setFont(new Font("BOLD",1,35));
     
    			keyButtons.add(n1);
    			keyButtons.add(n2);
    			keyButtons.add(n3);
    			keyButtons.add(n4);
    			keyButtons.add(n5);
    			keyButtons.add(n6);
    			keyButtons.add(n7);
    			keyButtons.add(n8);
    			keyButtons.add(n9);
    			keyButtons.add(start);
    			keyButtons.add(n0);
    			keyButtons.add(stop);
     
     
     
     
     
    			n1.addActionListener(this);
    			n2.addActionListener(this);
    			n3.addActionListener(this);
    			n4.addActionListener(this);
    			n5.addActionListener(this);
    			n6.addActionListener(this);
    			n7.addActionListener(this);
    			n8.addActionListener(this);
    			n9.addActionListener(this);
    			n0.addActionListener(this);
    			start.addActionListener(this);
    			stop.addActionListener(this);
     
     
     
     
     
     
    			JFrame dos = new JFrame();
    			dos.setSize(700,500);
    			dos.add(keyButtons,BorderLayout.EAST);
     
    			dos.add(screen,BorderLayout.WEST);
     
    			dos.add(North,BorderLayout.NORTH);
    			dos.add(South,BorderLayout.SOUTH);
    			dos.setVisible(true);
    			dos.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
     
     
    		}
     
     
    		public static void main (String args[]){
    			MicroWave GUI = new MicroWave();
    			GUI.launchFrame();
     
     
     
     
     
     
    		}
     
     
     
     
    }

    what should i do . so if ever i click ANY OF THE JBUTTON NUMBERS the "00:00:00" the COLON STILL APPEARS . WHAT SHOULD I ADD TO MY PROGRAM ANY SUGGESTION GUYS ?? HELP PLEASE

  15. #15
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: TIMER HELP PLEASE

    STOP YELLING

    What does this code do? What are you trying to accomplish exactly? What do you think the timer.replaceSelection() method does?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  16. #16
    Junior Member
    Join Date
    Sep 2014
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: TIMER HELP PLEASE

    im trying to do this "00:00:00" while i input numbers the colon " : " still appears every time i input numbers

  17. #17
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: TIMER HELP PLEASE

    I still don't really know what you're trying to do. Can you give us an example of how somebody would use your program?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  18. #18
    Junior Member
    Join Date
    Sep 2014
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: TIMER HELP PLEASE

    have you tried to run my program ?? well by the way what im trying to do is if i will input numbers the colon should appear to . but the problem is when i input numbers it will go straight EXAMPLE (123133) it should appear to be like this("12:31:33") everytime i will input numbers .

  19. #19
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: TIMER HELP PLEASE

    I have run your code.

    Where are you doing the formatting of the text so that it includes colons?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  20. #20
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: TIMER HELP PLEASE

    Threads merged and moved.

    Please do not start multiple threads on the same topic. Keep this one going until solved or a significantly different topic must be addressed.

  21. #21
    Junior Member
    Join Date
    Sep 2014
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: TIMER HELP PLEASE

    Quote Originally Posted by KevinWorkman View Post
    I have run your code.

    Where are you doing the formatting of the text so that it includes colons?
    none . thats why i post this thread to ask . can you help me ??

  22. #22
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: TIMER HELP PLEASE

    Quote Originally Posted by javados View Post
    none . thats why i post this thread to ask . can you help me ??
    I'm not going to do your work for you. If you want the String formatted, you're going to have to format the String. Google is your friend there. Why don't you try something and post an MCVE consisting ONLY of the formatting part (use a hard-coded String and print statements) if you can't get it working?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. [SOLVED] Need some help in a timer
    By Kerooker in forum What's Wrong With My Code?
    Replies: 80
    Last Post: April 28th, 2014, 03:14 PM
  2. [SOLVED] both class javax.swing.Timer in javax.swing and class java.util.Timer in java.util match
    By stresstedout in forum What's Wrong With My Code?
    Replies: 13
    Last Post: April 10th, 2014, 07:32 PM
  3. (Timer?) Problems
    By tyeeeee1 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: December 10th, 2012, 03:24 PM
  4. Timer digit
    By The_Mexican in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 2nd, 2011, 08:07 PM
  5. Timer?
    By TimW in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: October 27th, 2009, 07:43 AM