Re: [問題] 請問有關於 Exit JFrame的問題

看板java作者 (骨頭)時間16年前 (2008/06/30 10:35), 編輯推噓2(201)
留言3則, 3人參與, 最新討論串2/2 (看更多)
※ 引述《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

06/30 10:37, , 1F
突然想接:I am your father... (什麼鬼阿)
06/30 10:37, 1F

06/30 11:33, , 2F
謝謝TonyQ,實作windowClosing後,成功擁有我要的功能了^^
06/30 11:33, 2F

06/30 11:51, , 3F
加油吧 ~_~
06/30 11:51, 3F
文章代碼(AID): #18Q4PzNY (java)
文章代碼(AID): #18Q4PzNY (java)