Scala Swing smallest possible application

In comparison to the smallest possible Java Swing application posted before here, this is the Scala way of doing it. Scala is a modular language that is not shipping with one big jdk like Java does but with rather independent jars per functionality like scala-swing, scala-actors. The scala-swing is a light wrapper on Java Swing providing Scala-esque feel to it.

import swing._

object HelloWorld extends SimpleSwingApplication {
  def top = new MainFrame {
    title = "Hello, World!"

Things to note:
– We don’t need to start on independent thread or start with main method. The provided SimpleSwingApplication is doing all these for us.
MainFrame is a wrapper around JFrame
– By calling peer we are getting access on the methods of the underlying JFrame.
– Notice that we don’t have to set visible the frame or shutdown the application on close because it is done for us from the underlying MainFrame.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s