Hello All,
I've tried everything I know but I'm stuck on setting a JFrame to setVisibility(false), after a timer goes off. My intention is to have a JFrame go off screen but still running in the background. Then, after the timer goes off again, its visible again on screen. The attached code is simple but if I can get the theory down I will apply to a much bigger program. Also, can anyone tell me how to check if a JFrame is visible. There is a method call isShowing(), but I can't get it to work either.
Thanks in advance, Ray
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Frame {
JFrame frame;
JPanel panel;
Frame(
String str) {
frame = new JFrame(str);
panel = new JPanel();
panel.setPreferredSize(new Dimension(500,500));
frame.getContentPane().add(panel, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
class TimeKeeper {
Timer time;
TimeKeeper() {
time = new Timer(5000, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
// Need help here Frame.frame.setVisible(false);
}
});
}
}
public class
Test {
public static void main(String[] args) {
Frame newFrame = new Frame("Test Frame");
TimeKeeper timer = new TimeKeeper();
timer.time.start();
}
}