Mercurial Hosting > luan
comparison 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 |
comparison
equal
deleted
inserted
replaced
1615:38894708bade | 1616:915cb538e2a3 |
---|---|
1 local Luan = require "luan:Luan.luan" | |
2 local error = Luan.error | |
3 local set_metatable = Luan.set_metatable or error() | |
4 require "java" | |
5 local JFrame = require "java:javax.swing.JFrame" | |
6 | |
7 | |
8 local Frame = {} | |
9 | |
10 local mt = {} | |
11 | |
12 function mt.__index(frame,key) | |
13 if key == "visible" then | |
14 return frame.java.isVisible() | |
15 end | |
16 error("'"..key.."' not defined") | |
17 end | |
18 | |
19 function mt.__new_index(frame,key,value) | |
20 if key == "visible" then | |
21 frame.java.setVisible(value) | |
22 return | |
23 end | |
24 error("'"..key.."' not defined") | |
25 end | |
26 | |
27 function Frame.new(title) | |
28 local jframe = JFrame.new(title) | |
29 local frame = { java = jframe } | |
30 function frame.exit_on_close() | |
31 jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
32 end | |
33 function frame.add(component) | |
34 jframe.add(component.java) | |
35 end | |
36 frame.pack = jframe.pack | |
37 set_metatable(frame,mt) | |
38 return frame | |
39 end | |
40 | |
41 return Frame |