view src/luan/modules/swing/Frame.luan @ 1735:4b56eff90040 default tip

add hosting.html
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 02 Oct 2022 17:32:00 -0600
parents 915cb538e2a3
children
line wrap: on
line source

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