0

クラス内でグルーヴィーな 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();
  }

フレームがオブジェクトであるため、 self を使用する必要があるかどうかわかりませんか? 私のフレーム変数の定義は、使用しようとしている範囲外のようです。

助けていただければ幸いです、ありがとう。

4

1 に答える 1

0

インスタンス化から宣言を単純に分割する必要があります。

def frame
frame = swing.frame(...)
于 2019-02-28T13:07:29.347 に答える