0

I'm trying to define my groovy FX frame "frame" within a class. I then have a button that does "frame.setenabled(false)" but for some reason "frame" cannot be found.

My code :

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);

My initialization code is :

  public static void main(String[] args) {
    new Contact_Books();
  }

Im not sure if because frame is an object i need to use self ? It seems that my definition of the frame variable is outside the scope of where I'm trying to use it.

Any help would be appreciated , thanks.

1 Answers1

0

You should simply split declaration from instantiation:

def frame
frame = swing.frame(...)
injecteer
  • 20,038
  • 4
  • 45
  • 89