Objectives

Students will be able to:

  • grasp the concept that using libraries increases the speed and testing of development
  • gain an appreciation of Object Oriented Programming
  • use Java Swing components to make a gui-based Tic Tac Toe game

Tic Tac Toe

Tic Tac Toe

We will design a Tic Tac Toe game with a Graphical User Interface (GUI).

We will need a game frame and buttons and ... it will be very compliated to code these things.

 

But wait... we can borrow code from the Java Swing library.

It has components that we can use and also redesign if necessary for our own purposes.

Java Swing has the following components ... and many more:

  • JFrame - a frame to host the GUI
  • JButton - click a button!
  • JTextBox - type some text
  • etc

Without these components, you would need to do do a lot of coding to design your own!

Library Files - Advantages

So, using the Java Swing library (or any library file(s)):

  • saves you time when developing code
  • save you time testing because the code is already tested
  • helps reduce errors because the code has already been tested

Starter Video

The following video will cover these concepts and show you how to develop the game frame hosting 9 clickable buttons!

Game Logic Part 1

Let's get started with the game logic. Every time we click a button, we trigger an event.

Game Logic Part 2

Let's conclude the game logic and play the game!

Tags

implements this.add(buttons[i]) GameFrame extends setTitle() new DisplayGrid(3,3) class ActionListener() for() public JFrame new private JButton


SUBSCRIBE

Join my mailing list to receive updates on the latest blog posts and other things.