Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Creating Swing DSL with Kotlin

Creating Swing DSL with Kotlin

Presentation for first ever Kotlin Bosnia meetup held in Banja Luka.

This talk is live coding session aimed to present how Kotlin can help as in working with old Java toolkits such as Swing. The end result of talk is a small DSL for Swing that transforms Swing GUI components into more readable and concise code structures.

Code sample:
https://github.com/Vuksa/SwingDSL/tree/dsl_complete

Nebojša Vukšić

October 06, 2017
Tweet

More Decks by Nebojša Vukšić

Other Decks in Programming

Transcript

  1. Nebojša Vukšić Android developer @ codecentric Founder of Kotlin User

    Group Serbia TheTechW0lf https://github.com/Vuksa
  2. What is Kotlin? statically-typed object oriented programming language targeting JVM,

    Android and JavaScript fully interoperable with Java third party library has excellent IDE support Google acknowledged
  3. What is Kotlin? statically-typed object oriented programming language targeting JVM,

    Android and JavaScript fully interoperable with Java third party library
  4. What is Kotlin? statically-typed object oriented programming language targeting JVM,

    Android and JavaScript fully interoperable with Java third party library has excellent IDE support
  5. What is Kotlin? statically-typed object oriented programming language targeting JVM,

    Android and JavaScript fully interoperable with Java third party library has excellent IDE support Google acknowledged
  6. Kotlin history developed by JetBrains unveiled to public in 2011.(development

    started in 2012.) 1.0 first stable version (February 2016.) current version 1.2 Beta
  7. DSL by Wikipedia A domain-specific language (DSL) is a computer

    language specialized to a particular application domain.
  8. What is Swing? GUI widget toolkit in Java introduced in

    1997 A Swing GUI consists of components and containers
  9. What is Swing? GUI widget toolkit in Java introduced in

    1997 A Swing GUI consists of components and containers Swing components are lightweight and don’t rely on peers
  10. What is Swing? GUI widget toolkit in Java introduced in

    1997 A Swing GUI consists of components and containers Swing components are lightweight and don’t rely on peers supports pluggable look and feel
  11. Swing GUI code JFrame jfrm = new JFrame("A Simple Swing

    Program"); // Give the frame an initial size. jfrm.setSize(275, 100); // Terminate the program when the user closes the application. jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create a text-based label. JLabel jlab = new JLabel(" Swing powers the modern Java GUI."); // Add the label to the content pane. jfrm.getContentPane().add(jlab); // Display the frame. jfrm.setVisible(true);
  12. How we would like it to look like? frame(title =

    "A Simple Swing Program") { size = 275 x 100 defaultCloseOperation = EXIT_ON_CLOSE isVisible = true label(label = "Swing powers the modern Java GUI.") { } }
  13. Other Kotlin DSLs • Anko - dsl for Android •

    Kobalt - dsl like build system • Kaadin - dsl for Vaadin • TornadoFX - JavaFx dsl framework
  14. Resources to learn more • Official Kotlin documentation • Official

    Kotlin Github • Kotlin koans • Anko • TornadoFX • Kaadin • Kobolt • Awesome Kotlin – collection of materials • Slack kanal
  15. Nebojša Vukšić Android developer @ codecentric Founder of Kotlin User

    Group Serbia [email protected] Kotlin User Group Serbia https://www.meetup.com/Serbia-Kotlin-User-Group https://www.facebook.com/kotlinserbia/ https://twitter.com/kotlin_serbia TheTechW0lf