Mercurial Hosting > luan
diff src/luan/modules/swing/Frame.luan @ 1616:915cb538e2a3
start swing
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 05 Jun 2021 21:42:29 -0600 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/luan/modules/swing/Frame.luan Sat Jun 05 21:42:29 2021 -0600 @@ -0,0 +1,41 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local set_metatable = Luan.set_metatable or error() +require "java" +local JFrame = require "java:javax.swing.JFrame" + + +local Frame = {} + +local mt = {} + +function mt.__index(frame,key) + if key == "visible" then + return frame.java.isVisible() + end + error("'"..key.."' not defined") +end + +function mt.__new_index(frame,key,value) + if key == "visible" then + frame.java.setVisible(value) + return + end + error("'"..key.."' not defined") +end + +function Frame.new(title) + local jframe = JFrame.new(title) + local frame = { java = jframe } + function frame.exit_on_close() + jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + end + function frame.add(component) + jframe.add(component.java) + end + frame.pack = jframe.pack + set_metatable(frame,mt) + return frame +end + +return Frame