我正在尝试在一个类中定义我的 groovy FX 框架“框架”。然后我有一个执行“frame.setenabled(false)”的按钮,但由于某种原因找不到“frame”。
我的代码:
class Contact_Books extends JFrame {
public Contact_Books() {
@Grapes([
@Grab(group='org.xerial',module='sqlite-jdbc',version='3.23.1'),
@GrabConfig(systemClassLoader=true)
])
def sql = Sql.newInstance("jdbc:sqlite:Contacts.db", "org.sqlite.JDBC")
def contact = sql.dataSet("Contacts")
//Define Fonts
Font title = new Font("Serif", Font.BOLD, 30)
Font sub_title = new Font("Serif", Font.BOLD, 17)
Font Name = new Font("Serif", Font.BOLD, 20)
Font Ok_Button = new Font("Serif", Font.BOLD, 15)
Font Contact_Add_Button = new Font("Serif", Font.BOLD, 15)
Font bottom_buttons = new Font("Serif", Font.BOLD, 14)
def result = sql.firstRow('select count(*) as cont from Contacts WHERE name != "none"')
long Number_Of_Contacts = result.cont
def swing = new SwingBuilder()
def frame = swing.frame(title: "James' Contact Book", pack: true, visible: true, defaultCloseOperation: WC.HIDE_ON_CLOSE)
{
panel(id: 'mainPanel') {
scrollPane(verticalScrollBarPolicy: JScrollPane.VERTICAL_SCROLLBAR_ALWAYS) {
vbox {
label(" You have $Number_Of_Contacts contacts", constraints: "align center, span 6").setFont(title)
label(" Press more to see more information").setFont(sub_title)
(0..Number_Of_Contacts + 100).each { num ->
def pane = panel(alignmentX: 0f, background: java.awt.Color.LIGHT_GRAY, layout: new GridLayout(1, 2)) {
sql.eachRow("select rowid, * from Contacts WHERE rowid = $num+1") {
if ("$it.name" != 'none') {
label(" $it.name").setFont(Name)
}
if ("$it.name" != 'none') {
more = button(id: "buttonpanel$num", text: "More", actionPerformed: {
frame.setEnabled(false);
我的初始化代码是:
public static void main(String[] args) {
new Contact_Books();
}
我不确定是否因为 frame 是我需要使用 self 的对象?看来我对框架变量的定义超出了我尝试使用它的范围。
任何帮助将不胜感激,谢谢。