Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java Swing Timer

SharpStu
SharpStu 


I am looking for someone to make me a Swing Timer in Java that will be used for a fighting game. Information on the task: My task is to create a Swing Timer that counts down from 60 to 0, including zero, and prints out how many seconds it has left to the console. The timer doesn't respond to events directly. It responds to them indirectly by pausing when another condition is met in the code. That condition is when one player wins before the timer finishes counting. When the timer finishes counting, it should launch the appropriate logic depending on the state of the game. The count should remain 60 because once a second you post it and then decrement it by one. That value will be the way that we know how many seconds are left in a match. Also I want to take the timer and initialize it and store a reference to that timer in a variable in the VersusView class, and replace the action listener with a lambda expression. Attachments Tags Clarifications

Answers

Java Swing Timer

mariobeka
mariobeka 



I implemented the timer as a swing, add comments to what i did change and implemented the action listener as a lambda expression as asked. Also explained how you can get the timer set in the class VersusView. Attachments
Timer3.java (1 K) Download Preview
javax.swing.JLabel; import javax.swing.SwingUtilities; import javax.swing.Timer; public class Timer3 extends JFrame { private int count = 60; private int delay = 1000; public static final JLabel label = new JLabel(); public Timer3() throws HeadlessException { initUI(); } private void initUI()

VersusView.java (1 K) Download Preview
} /** * Paints the stage background. * * @param g a Graphics object to do the rendering */ @Override protected void paintComponent(Graphics g) { g.drawImage(img, 0, 0, getWidth(), getHeight(), this); } public void startThreads() { setStageAttributes(); } public void stopThreads() { } /* * Sets

Screen Shot 2014-04-28 at 10.37.28 PM.png (21 K) Download Preview

Screenshots
Screenshot
Purchase Answer