Jump to content

How can I let a frame exit by itself after few seconds

- - - - -

  • Please log in to reply
8 replies to this topic

#1
xxxxjayxxx

xxxxjayxxx

    Programmer

  • Members
  • PipPipPipPip
  • 123 posts
I just create a program. After I click exit a "Thank You" frame will appear.

How can I make the "Thank You" frame disappear after few sec by itself without letting the user to click on X button.

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
use the dispose() method.

#3
xxxxjayxxx

xxxxjayxxx

    Programmer

  • Members
  • PipPipPipPip
  • 123 posts
ok ... I just try dispose method ... The frame closes immediately.

Is there any chance that I can set a timer ? So that when the time is up the frame will closes by itself.

#4
Sinipull

Sinipull

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 386 posts
TimeUnit.SECONDS.sleep(3);

#5
xxxxjayxxx

xxxxjayxxx

    Programmer

  • Members
  • PipPipPipPip
  • 123 posts
Editted found some errors

Edited by xxxxjayxxx, 10 August 2011 - 08:15 AM.


#6
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Do the dispose after the sleep...

#7
Sinipull

Sinipull

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 386 posts
Put the sleep-code right before your message then... currently it's at the end.
put it before:

tyFrame.setVisible(true);

#8
Kibet

Kibet

    Newbie

  • Members
  • Pip
  • 1 posts
You can use the java.awt.Robot class where you
make the robot move the mouse to the close button. Then make it
press the mouse button and release automaticaly.
e.g.
Robot r=new Robot();
r.mouseMove(x,y);//where x and y are cordinate positions of close button
r.mousePress(KeyEvent.BUTTON1_MASK);//Left mouse button
r.mouseRelease((KeyEvent.BUTTON1_MASK);

for timing use:
r.sleep(t);//where t is in milliseconds
Hope this will help

#9
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java

Kibet said:

You can use the java.awt.Robot class where you
make the robot move the mouse to the close button. Then make it
press the mouse button and release automaticaly.
e.g.
Robot r=new Robot();
r.mouseMove(x,y);//where x and y are cordinate positions of close button
r.mousePress(KeyEvent.BUTTON1_MASK);//Left mouse button
r.mouseRelease((KeyEvent.BUTTON1_MASK);

for timing use:
r.sleep(t);//where t is in milliseconds
Hope this will help
That's actually a bad idea, not only makes it things way more complicated than it has to be, there are many cases where that will fail due to, for example, the frame being minimized or the frame being overlapped by any other program.
Besides, it's not really user friendly to go steal their mouse.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users