File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Stuck on setVisible() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Stuck on setVisible()" Watch "Stuck on setVisible()" New topic

Stuck on setVisible()

ray ramos 02

Joined: Aug 30, 2001
Posts: 2
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);
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();
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Ray,
IMO, your Timer Class will cause you problems because it doesn't have enough information to really do anything. You should combine the Frame and Timer classes into one class and call it TimerFrame. Then the problem becomes much more manageable and easy. The code below performs the trick.

ray ramos 02

Joined: Aug 30, 2001
Posts: 2
Ahhhh yes, I see it now.
Thanks for your help, Manfred
I agree. Here's the link:
subject: Stuck on setVisible()
It's not a secret anymore!