그루비에서 SWT를 쓰는 방법 (먼저 자바1.4 또는 자바 5를 설치해주세요.)
0. 그루비를 설치한다. (요즘 안정버전은 1.5.7이다)
1. Eclipse-libs.ZIP을 다운로드 받는다.
2. 파일을 WORK/lib 에 푼다. (WORK는 작업디렉토리)
3. WORK 디렉토리에 r.groovy 파일을 만들고 다음과 같이 적는다.
http://groovy.codehaus.org/GroovySWT 에서 베껴왔다.
0. 그루비를 설치한다. (요즘 안정버전은 1.5.7이다)
1. Eclipse-libs.ZIP을 다운로드 받는다.
2. 파일을 WORK/lib 에 푼다. (WORK는 작업디렉토리)
3. WORK 디렉토리에 r.groovy 파일을 만들고 다음과 같이 적는다.
def loader = this.class.classLoader.rootLoader
def dir = new File('lib')
dir.eachFileMatch(~/.*\.jar$/) {
loader.addURL(it.toURL())
}
evaluate(new File('test.groovy'))
4. test.groovy 에는 다음과 같이 적는다
import org.eclipse.swt.SWT
import org.eclipse.swt.widgets.*
def swt = new groovy.swt.SwtBuilder()
def shell = swt.shell(text:'Groovy / SWT Test') {
rowLayout()
label(style:"none", text:'Simple demo of Groovy and SWT')
button(style:"push", text:' Push Me ') {
onEvent(type:"Selection", closure:{ println "Hello" })
}
}
shell.pack()
shell.open()
while (!shell.disposed) {
if (!shell.display.readAndDispatch()) shell.display.sleep()
}
5. 이제, 프롬프트에서 다음 명령을 내리면 화면에 SWT로 만든 어플리케이션이 보인다.
C:\WORK\>groovy r.groovy
http://groovy.codehaus.org/GroovySWT 에서 베껴왔다.

