0

I have a GUI clock in Java (intelliJ 14) that uses a simple timer to update, when I run the program from IntelliJ the timer and clock work fine. However, when I export the project as an executable .jar file, and run it, the timer doesn't run at all, causing the clock to freeze.

Code for the clock:

private static final JLabel Clock = new JLabel("");
protected static final DateFormat CLOCK_FORMAT = new SimpleDateFormat("hh:mm:ss a");

    Clock.setBounds(482, 360, 135, 35);
    contentPane.add(Clock);
    Clock.setFont(new Font("DS-Digital", Font.PLAIN, 27));
    Timer timer = new Timer(1000, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                updateClock();
            }
     });
        timer.start();

updateClock():

    protected void updateClock() {

        Clock.setText(CLOCK_FORMAT.format(System.currentTimeMillis()));

    }

Whenever I run this from IntelliJ it works perfectly fine, but if I export it as a .jar the timer is never called. Any help would be great, thanks in advance!

Arman
  • 615
  • 2
  • 6
  • 20
  • 1- Add some `System.out.println` statements in your code to track the path of the method calls. 2- Run the Jar file from the command line and check the output, continue to add/remove print statements as need... – MadProgrammer Nov 28 '14 at 00:49
  • @MadProgrammer Alright I figured out the problem by doing this. Thanks! – Arman Nov 28 '14 at 01:01
  • What is the solution / problem you figured out ? others may use the tip. – UCJava Jan 15 '16 at 19:08

0 Answers0