Assuming that your timer repeats, inside the Timer's ActionListener check to see if it is running its last repeat, and if so, there, call the continueOrSomethingIdk()
method.
Otherwise you're going to have to rig your own notification mechanism, a call-back so that the timer notifies any listeners that it has completed running.
For example:
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
@SuppressWarnings("serial")
public class WhenTimerDone extends JPanel {
private static final Color[] COLORS = {
Color.RED, Color.ORANGE,
Color.YELLOW, Color.GREEN,
Color.BLUE, Color.CYAN };
private static final String START = "Start";
private static final String DONE = "Done";
private static final int PREF_W = 400;
private static final int PREF_H = PREF_W;
public static final int TIMER_DELAY = 1000;
private JLabel statusLabel = new JLabel(START);
private StartAction startAction = new StartAction("Start!");
public WhenTimerDone() {
add(statusLabel);
add(new JButton(startAction));
}
@Override
public Dimension getPreferredSize() {
if (isPreferredSizeSet()) {
return super.getPreferredSize();
}
return new Dimension(PREF_W, PREF_H);
}
// this is the method called by the Timer's ActionListener when it is done
public void done() {
// reset all to baseline state
statusLabel.setText(DONE);
startAction.setEnabled(true);
setBackground(null);
}
// ActionListener for the start button
private class StartAction extends AbstractAction {
public StartAction(String name) {
super(name);
int mnemonic = (int) name.charAt(0);
putValue(MNEMONIC_KEY, mnemonic);
}
@Override
public void actionPerformed(ActionEvent e) {
// disables itself
setEnabled(false);
statusLabel.setText(START); // updates the status label
// create and start a timer
Timer timer = new Timer(TIMER_DELAY, new TimerListener());
timer.setInitialDelay(0);
timer.start();
}
}
// action listener for the timer
private class TimerListener implements ActionListener {
private int colorsIndex = 0;
@Override
public void actionPerformed(ActionEvent e) {
// simply loops through a colors array, changing background color
if (colorsIndex < COLORS.length) {
setBackground(COLORS[colorsIndex]);
colorsIndex++;
} else {
// when all colors shown -- stop the timer
((Timer) e.getSource()).stop();
// and call the done method -- ******* here's the key!
done(); // called when Timer is done!
}
}
}
private static void createAndShowGui() {
WhenTimerDone mainPanel = new WhenTimerDone();
JFrame frame = new JFrame("WhenTimerDone");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(mainPanel);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> createAndShowGui());
}
}