• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Stuck on setVisible()

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}
}
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ahhhh yes, I see it now.
Thanks for your help, Manfred
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic