Skip to content

Part 2 — GUI with Swing

2 lectures (CM) · 3 lab sessions (TD) · Autonomous project (BE1)

Why Swing and not JavaFX? Swing ships with the JDK (zero setup), and its model — components, layout managers, listeners, custom paintComponent() — maps directly onto what you will meet again in Android (views, layouts, click listeners, Canvas). We use it as a concept vehicle, not because it is the most modern desktop toolkit (that would be JavaFX).

Objectives

By the end of Part 2 you will be able to:

  • Build a Swing GUI with JFrame, JPanel, and layout managers
  • Connect UI events to model objects via ActionListener
  • Override paintComponent() to draw custom graphics
  • Capture mouse clicks and translate them to game coordinates
  • Build a complete two-player game application

Thread: from Car UI to Spider Game

  • CM4/TD4CarUI: control panel for the Car from Part 1
  • CM5/TD5GridPanel: 3×3 interactive drawing component
  • Project BE1 — Spider Game: full two-player game using everything from Parts 1 and 2

Resources

Resource Link
CM4 slides PDF
CM5 slides PDF
TD4 Car Control Panel
TD5 Drawing Canvas & Grid
TD-Threads Concurrency & SwingWorker
Project BE1 Spider Game