我的漫漫程序之旅

          專注于JavaWeb開發
          隨筆 - 39, 文章 - 310, 評論 - 411, 引用 - 0
          數據加載中……

          Groovy之旅系列之七(Groovy Swing)

          也許你對先前的Groovy程序有點煩了,全是控制臺程序,現在我們
          來體驗一下它的界面程序吧.

          package com

          import groovy.swing.SwingBuilder 
          import java.awt.BorderLayout 
          //聲明一個SwingBuilder
          def swing = new SwingBuilder()
          //計數器 
          count = 0
          //聲明一個label
          def textlabel
          //聲明一個frame
          def frame = 
          swing.frame(title:
          '計數器', size:[300,300]) 

              borderLayout() 
              textlabel 
          = label(text:"您還未點擊,Come on!"
              constraints: BorderLayout.NORTH) 
              button(text:
          'Click Me'
              actionPerformed: {count
          ++; textlabel.text = "您已經點擊了${count}次."; println "clicked"}, 
              constraints:BorderLayout.SOUTH) 

          //控件自適應窗口大小
          frame.pack()
          //顯示
          frame.show()
          再來一個,自己運行一下就知道,用groovy寫Swing程序是多么簡單了.

          package com

          import groovy.swing.SwingBuilder 
          import javax.swing.* 
          import java.awt.* 

          def swing 
          = new SwingBuilder() 
          //聲明一個共用的Panel
          def sharedPanel = 

              swing.panel() { 
              label(
          "共享Panel"
              } 


          count 
          = 0 
          def textlabel 
          def frame 
          = 
              swing.frame(title:
          '共享Panel救命', size:[300,300], defaultCloseOperation:JFrame.EXIT_ON_CLOSE, pack:true
              show:
          true) { 
              boxLayout(axis:BoxLayout.Y_AXIS) 
              textlabel 
          = label(text:"點擊了${count}次."
              constraints: BorderLayout.NORTH) 
              button(text:
          '點擊我'
              actionPerformed: {count
          ++; textlabel.text = "點擊了${count}次"; println "clicked"}, 
              constraints:BorderLayout.SOUTH) 
              widget(sharedPanel()) 
              widget(sharedPanel()) 
          }




          posted on 2008-05-15 15:48 々上善若水々 閱讀(1852) 評論(1)  編輯  收藏

          評論

          # re: Groovy之旅系列之七(Groovy Swing)  回復  更多評論   

          cool!!!
          2008-05-16 10:53 | hcom

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 镇平县| 张掖市| 五莲县| 长垣县| 普安县| 延寿县| 林口县| 云安县| 扬州市| 炎陵县| 棋牌| 安福县| 峨边| 卢氏县| 咸宁市| 汝南县| 醴陵市| 白山市| 闵行区| 普兰店市| 登封市| 无棣县| 贺州市| 吉水县| 峨边| 浏阳市| 马公市| 绿春县| 武夷山市| 讷河市| 北碚区| 东光县| 龙里县| 南通市| 嘉义县| 肇源县| 吉林省| 赣州市| 翁源县| 仁寿县| 宁强县|