使用 Jruby 覆盖 JFrame 中默认关闭操作的正确方法是什么?我尝试了以下方法,但是只能通过单击窗口装饰关闭按钮来关闭窗口。
JFrame初始化方法
def initialize *args
super("Attendance")
self.setDefaultCloseOperation(javax.swing.JFrame::DO_NOTHING_ON_CLOSE)
self.add_window_listener(CloseHelper.new)
self.minimum_width = FRAME_WIDTH
self.minimum_height = FRAME_HEIGHT
base_font = Font.new("Lucida Grande", 0, 14)
set_up_components
self.set_visible true
self.pack
end
WindowAdapter 类
class CloseHelper < WindowAdapter
def window_closing event
signouttime=DateTime.now
cdate=correct_date(signouttime,nil)
if cdate
AttendanceModel.fetch("update visitors set signedout=? where datediff(day,signedin,?)=0 and signedout is null",signouttime,signouttime).update
showerror("Message","Signed out all visitors",nil,nil)
end
java.lang.System.exit(0)
end
end