aspose file tools*
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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Stuck on setVisible()" Watch "Stuck on setVisible()" New topic
Author

Stuck on setVisible()

ray ramos 02
Greenhorn

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);
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();
}
}
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.

Enjoy,
Manfred.
ray ramos 02
Greenhorn

Joined: Aug 30, 2001
Posts: 2
Ahhhh yes, I see it now.
Thanks for your help, Manfred
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stuck on setVisible()