我试图在一个类中定义我的常规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?看来我对frame变量的定义超出了我尝试使用它的范围。
任何帮助,谢谢。
答案 0 :(得分:0)
您应该简单地从实例中拆分声明:
def frame
frame = swing.frame(...)