Skip to content

Instantly share code, notes, and snippets.

@bitsnaps
Created June 3, 2018 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitsnaps/59755f182865d39dc90d546fe97d64ce to your computer and use it in GitHub Desktop.
Save bitsnaps/59755f182865d39dc90d546fe97d64ce to your computer and use it in GitHub Desktop.
Simple AWT Gui App using what looks like Builder Pattern with Groovy
import java.awt.*
import java.awt.event.*
new Frame(title:"Hello AWT", size:[300, 200], locationRelativeTo: null, visible: true).with {
def tf = add({ new TextField(text:"www.google.com", bounds: [50,50,150,20])}() )
def l = add({ new Label(bounds: [50,100,250,20]) }())
add({
def b = new Button(label:"Find IP", bounds: [50,150,60,30])
b.addActionListener({ l.text = "IP of ${tf.text} is ${java.net.InetAddress.getByName(tf.text).hostAddress}" })
b}())
addWindowListener({ dispose() } as WindowAdapter)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment