so this is my update code where i have issue in formatting Timer in Java GUI..
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;
import javax.swing.border.EmptyBorder;
public class deploy extends JFrame {
private JPanel contentPane;
Timer tm;
Timer tm2;
int i = 0;
int o = 0;
public deploy() {
contentPane = new JPanel();
contentPane.setBackground(Color.DARK_GRAY);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblTimer2 = new JLabel("New label");
lblTimer2.setForeground(Color.WHITE);
lblTimer2.setFont(new Font("Tahoma", Font.PLAIN, 20));
lblTimer2.setBounds(295, 231, 182, 16);
contentPane.add(lblTimer2);
tm2 = new Timer(1000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
lblTimer2.setText(Integer.toString(o));
o++;
}
});
JButton btnNewButton = new JButton("Start");
btnNewButton.setBackground(Color.LIGHT_GRAY);
btnNewButton.setForeground(Color.BLUE);
btnNewButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
tm2.start();
}
});
btnNewButton.setBounds(289, 257, 89, 32);
contentPane.add(btnNewButton);
JButton btnNewButton_1 = new JButton("Stop");
btnNewButton_1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
tm2.stop();
}
});
pack();
setVisible(true);
}
public static void main(String[] args) {
new deploy();
}
}
this is the part in my code that i need your help guys..i want my lblTimer2 will display the format of "00:00". but my code i did here is formatted as "0" and so on.. because i'm creating a GUI cybercafe management software which the feature of my GUI is to time the client and after the client finish with his/her work the time will stop and it will compute the time he/she spent that it will go through billing transaction. i'm new in Programming and using Eclipse Neon for Java GUI Swing Application.