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 ?
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.
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 ?
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.
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 .
Threads merged.
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.
yeah like this . 00:00:00 then it will countdown
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.
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 ?
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.
can you explain it basically sir ?
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.
DONE ! how about the timer HH:MM:SS
Look at the Timer class in the swing package.
If you don't understand my answer, don't ignore it, ask a question.
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
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!
im trying to do this "00:00:00" while i input numbers the colon " : " still appears every time i input numbers
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!
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 .
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!
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.
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!