Skip to content

Instantly share code, notes, and snippets.

@caiorss
Last active October 22, 2016 19:12
Show Gist options
  • Save caiorss/dcdde7eae3da5acc84e6fc7f5237b82c to your computer and use it in GitHub Desktop.
Save caiorss/dcdde7eae3da5acc84e6fc7f5237b82c to your computer and use it in GitHub Desktop.
Simple Scala GUI script

Usage:

 $ chmod +x scala-gui-script.scala
 $ ./scala-gui-script.scala

or

  $ scala scala-gui-script.scala

Screenshot: http://imgur.com/a/pVTZ5

#!/usr/bin/env scala
import javax.swing.JFrame
import javax.swing.JButton
import javax.swing.JLabel
import java.awt.event.ActionEvent
import java.awt.event.ActionListener
import java.awt.GridLayout
val frame = new JFrame("Hello world Scala rocks!")
val btn = new JButton("Click me now!")
btn.addActionListener(new ActionListener() {
override def actionPerformed(event: ActionEvent){
println("I was clicked")
}
})
frame.setLayout(new GridLayout(3, 1))
frame.getContentPane.add(new JLabel("Scala GUI script"))
frame.getContentPane.add(btn)
frame.setSize(300, 400)
// frame.pack()
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
frame.setVisible(true)
frame.setLocation(100, 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment