Usage:
$ chmod +x scala-gui-script.scala
$ ./scala-gui-script.scalaor
$ scala scala-gui-script.scalaScreenshot: http://imgur.com/a/pVTZ5
Usage:
$ chmod +x scala-gui-script.scala
$ ./scala-gui-script.scalaor
$ scala scala-gui-script.scalaScreenshot: 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) |