作者TonyQ (骨头)
看板java
标题Re: [问题] 请问有关於 Exit JFrame的问题
时间Mon Jun 30 10:35:39 2008
※ 引述《seruze (seruze)》之铭言:
: 是这样的~
: 在我开启一个视窗後~
: 我想在关闭他时,同时可以执行一动作。
: 这样子的做法,我可以设一个「关闭」的BUTTON~
: 先执行我要的内容,然後再用JFrame.dispose();关闭他~
: 可是视窗右上角也有一个「x」的关闭按钮~
: 请问各位大大这时候,我该怎麽定义按「x」时会执行的动作呢?
api:
http://0rz.tw/744ob
jframeInst.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
这是预设的状况 按了就关闭
有三种选项可以选
DO_NOTHING_ON_CLOSE (defined in WindowConstants):
Don't do anything; require the program to handle the operation
in the windowClosing method of a registered WindowListener object.
HIDE_ON_CLOSE (defined in WindowConstants):
Automatically hide the frame
after invoking any registered WindowListener objects.
DISPOSE_ON_CLOSE (defined in WindowConstants):
Automatically hide and dispose the frame after invoking any
registered WindowListener objects.
EXIT_ON_CLOSE (defined in JFrame):
Exit the application using the System exit method. Use this only
in applications.
如果想要自己定义更多的行为
实做一个 WindowListener 并复写 windowClosing 就可以做到
记得以前在板上写过范例 , 不过大概标题下得太烂, 现在一时找不到...
api:
http://0rz.tw/dc4iv
--
API Document will be your friend ...:)
--
I am a person, and I am always thinking .
Thinking in love , Thinking in life ,
Thinking in why , Thinking in worth.
I can't believe any of what ,
I am just thinking then thinking ,
but worst of all , most of mine is thinking not actioning...
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.128.219.202
1F:推 PsMonkey:突然想接:I am your father... (什麽鬼阿) 06/30 10:37
2F:推 seruze:谢谢TonyQ,实作windowClosing後,成功拥有我要的功能了^^ 06/30 11:33
3F:→ TonyQ:加油吧 ~_~ 06/30 11:51