raw_suicide
Ex Member
noob programmer needs help with a "simple" program
Feb 26th , 2010, 3:55am
hi im new to prgramming and need help with a task we're set in college, we need to make a timer i.e. 00:00:00:00 hours minutes seconds milliseconds needs to be started witgh a start button, stopped with a stop button, reset with a reset button any insight would be helpful and greatly appreciated, if i need to move change remove or add anything plz tell me so yh... plzzzzz help package tasktimer; import java.awt.Dimension; import java.awt.Container; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.*; import javax.swing.JOptionPane; import javax.swing.JButton; import javax.swing.JFrame; import java.awt.event.*; import javax.swing.JTextField; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.*; import javax.swing.JButton; import javax.swing.Timer; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class TaskTimer extends JFrame implements ActionListener { private JButton start; private JButton stop; private JButton reset; private JPanel panel; private JOptionPane myOptionPane; private Timer myTimer; private JPanel drawingJPanel; private JLabel TimerDisplay; //private long startTime; //private long stopTime; public static void main(String[] args) { TaskTimer calculationFrame = new TaskTimer(); calculationFrame.setSize(400,400); calculationFrame.createGUI(); calculationFrame.setVisible(true); } public void createGUI() { setDefaultCloseOperation(EXIT_ON_CLOSE); Container window = this.getContentPane(); //window.setLayout(new FlowLayout()); panel = new JPanel(); panel.setPreferredSize(new Dimension(700,700)); panel.setBackground(Color.blue); panel.setLayout(null); window.add(panel); start = new JButton("start"); start.setBounds(40,45,100,20); panel.add(start); start.addActionListener(this); stop = new JButton("stop"); stop.setBounds(40,25,100,20); panel.add(stop); stop.addActionListener(this); reset = new JButton ("reset"); reset.setBounds(40,65,100,20); panel.add(reset); reset.addActionListener(this); TimerDisplay = new JLabel("0"); TimerDisplay.setBounds(200,200,500,20); TimerDisplay.setBackground(Color.red); TimerDisplay.setLayout(null); panel.add(TimerDisplay); TimerDisplay.setVisible(true); TimerDisplay.setForeground(Color.white); } public void actionPerformed(ActionEvent e) { if (e.getSource() == myTimer) if (drawingJPanel.getBackground() == Color.blue) { drawingJPanel.setBackground(Color.red); } else drawingJPanel.setBackground(Color.blue); int startingTime; int m = millis(); int seconds = m / 1000; int minutes = seconds / 60; int hours = minutes / 60; int days = hours / 24; seconds -= minutes * 60; minutes -= hours * 60; hours -= days * 24; String format = "This timer has been running for {0,number,integer} days {1,number,integer} hours {2,number,integer} minutes and {3,number,integer} seconds"; startingTime = millis(); } private int millis() { throw new UnsupportedOperationException("Not yet implemented"); } }