1 / 13

CrossWord Puzzle - Fun and Interactive Word Game

Create and solve crossword puzzles using Java's JApplet, JPanels, and JComboBoxes. Load words and clues from a text file and challenge yourself with this interactive word game!

aclifton
Download Presentation

CrossWord Puzzle - Fun and Interactive Word Game

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CrossWord Puzzle By Keith Lynn Field Trip #31

  2. JApplet • A JApplet is a top-level container in Java • We will use the JApplet to contain two Jpanels • The first JPanel will contain letters • The second JPanel will contain words • In order to load a JApplet, we create an HTML document • The HTML document must contain an applet tag • The applet tag must contain the applet's name, width, and height

  3. Appletviewer • An alternative to using a browser is to use the appletviewer program that is included in the JDK • In order to use the appletviewer program, we create an HTML document where we include an applet tag • The applet tag must contain the name of the class, the width and height

  4. LayoutManager • A LayoutManager defines how components will be placed onto a screen • There are built-in layout managers in Java • FlowLayout will put components in a row • GridLayout will put components in a grid • In this app, we will create a Jpanel to hold letters in buttons and put the buttons in a grid

  5. String • A String is a collection of individual characters • We can obtain the character at a certain position in a String with the method charAt(int) • The first character in a String is at position 0 • We can determine the length of the String with the length() method • We can concatenate characters to String with the += operator • We can compare the content of two Strings with the equals or equalsIgnoreCase methods

  6. Characters • A character is a single character • There is a special relationship between chars and ints in Java • If you treat a char like an int, it is converted to its ASCII equivalent

  7. JComboBox • A JComboBox is a selection list • It will contain a list of items • In this app, we will create many JComboBoxes that contain the letters of the alphabet

  8. JButton • A JButton is a component that can be placed on a container • The JButton can contain text or an image • In this app, we will provide the user with button to give up

  9. Events • We can detect events and act on them by creating an event listener • An event listener we can use with a button is the ActionListener • ActionListener is an interface which contains the method actionPerformed • If an ActionListener is registered with a button, then when the button is clicked, actionPerformed is called

  10. Events, cont'd • The event listener we will use with the JComboBoxes is the ItemListener • The ItemListener interface contains the method itemStateChanged • We can determine whether the state change was ItemEvent.SELECTED or ItemEvent.DESELECTED by using the method getStateChange • Note that selecting an item in a JComboBox causes both a deselection and a selection event

  11. Arrays • Arrays are a collection of elements of the same type • In our app, we will use a 2 dimensional array • Java doesn't directly support 2 dimensional arrays • But we can create an array of arrays • We write a 2 dimensional array of 20 x 20 containing JcomboBoxes • However, we will black out some boxes

  12. Filling in Words • We choose beforehand to black out certain boxes leaving only 26 positions to be filled with words • Some of those words overlap • We will load from a text file a list of words and definitions and choose 26 words randomly • We make sure that we choose words that have the correct letters if the words overlap

  13. The Game • After the list of words and clues are loaded and we have chosen the words, we will display the clue for the word in a JComboBox • The JComboBoxes corresponding to the word that goes with the clue will be highlighted in red • If the user correctly chooses the letters, then the JComboBoxes are highlighted in green • If the user gives up, then all of the words are displayed and all JComboBoxes that contains letters of words are highlighted in green

More Related