单击按钮时如何更新面板中的 groovy 图像?

how I could update groovy image in panel when click a button?

我正在尝试使用此代码在面板中显示图像,然后在单击时更新图像但不起作用(不更新图像)

出现此错误:

Exception in thread "AWT-EventQueue-0" groovy.lang.MissingPropertyException: No such property: label

不知道怎么更新。

这是我的代码:

@Bindable
class Address { 
    String street, number, city
    String toString() { "address[street=$street,number=$number,city=$city]" }
} 



def address = new Address(street: 'Evergreen Terrace', number: '742', city: 'Springfield')
   def BL = new BorderLayout()

def swing = new SwingBuilder()
def swingBuilder = new SwingBuilder()
swingBuilder.edt {  // edt method makes sure UI is build on Event Dispatch Thread.


    lookAndFeel 'nimbus'  // Simple change in look and feel.

    frame(title: 'Address', size: [1000, 800],
            show: true, locationRelativeTo: null,

            defaultCloseOperation: EXIT_ON_CLOSE) {

        borderLayout(vgap: 5)

        panel(constraints: BorderLayout.CENTER,
                border: compoundBorder([emptyBorder(10), titledBorder('Enter your address:')])) {
            tableLayout {

                tr {
                    td {
                        label 'Street:'  // text property is default, so it is implicit.
                    }
                    td {
                        textField address.street, id: 'streetField', columns: 20
                    }
                }
                tr {
                    td {
                        label 'Number:'
                    }
                    td {
                        textField id: 'numberField', columns: 5, text: address.number
                    }
                }
                tr {
                    td {
                        label 'City:'
                    }
                    td {
                        textField id: 'cityField', columns: 20, address.city
                    }
    td {
                        textField id: 'cityField', columns: 20, address.city
                    }
                }
            }


      scrollPane(id:'scroll',preferredSize: [200,200], constraints: context.CENTER) {



    panel(layout: new FlowLayout()) {


        label(icon: imageIcon(new URL('pokemon.png')))
    }


      }





      }







        panel(constraints: BorderLayout.SOUTH) {
            button text: 'Save', actionPerformed: {
                println address
label.setIcon('pokemon.png');
            }
        }

        // Binding of textfield's to address object.
        bean address,
            street: bind { streetField.text },
            number: bind { numberField.text },
            city: bind { cityField.text }
    } 
}

我用这个解决

@Bindable
class Address { 
    String street, number, city
    String toString() { "address[street=$street,number=$number,city=$city]" }
} 



def address = new Address(street: 'Evergreen Terrace', number: '742', city: 'Springfield')
   def BL = new BorderLayout()

def swing = new SwingBuilder()
def swingBuilder = new SwingBuilder()
swingBuilder.edt {  // edt method makes sure UI is build on Event Dispatch Thread.


    lookAndFeel 'nimbus'  // Simple change in look and feel.

    frame(title: 'Address', size: [1000, 800],
            show: true, locationRelativeTo: null,

            defaultCloseOperation: EXIT_ON_CLOSE) {

        borderLayout(vgap: 5)

        panel(constraints: BorderLayout.CENTER,
                border: compoundBorder([emptyBorder(10), titledBorder('Enter your address:')])) {
            tableLayout {

                tr {
                    td {
                        label 'Street:'  // text property is default, so it is implicit.
                    }
                    td {
                        textField address.street, id: 'streetField', columns: 20
                    }
                }
                tr {
                    td {
                        label 'Number:'
                    }
                    td {
                        textField id: 'numberField', columns: 5, text: address.number
                    }
                }
                tr {
                    td {
                        label 'City:'
                    }
                    td {
                        textField id: 'cityField', columns: 20, address.city
                    }
    td {
                        textField id: 'cityField', columns: 20, address.city
                    }
                }
            }


          scrollPane(id:'scroll',preferredSize: [200,200], constraints: context.CENTER) {



        panel(layout: new FlowLayout()) {


    imagelabelx=        label(icon: imageIcon(new URL('pokemon.png')))
        }


          }





          }







            panel(constraints: BorderLayout.SOUTH) {
                button text: 'Save', actionPerformed: {
                    println address
    imagelabelx.icon= imageIcon(new URL('pokemon2.png'))
                }
            }

            // Binding of textfield's to address object.
            bean address,
                street: bind { streetField.text },
                number: bind { numberField.text },
                city: bind { cityField.text }
        } 
    }