Compsci 108, Spring 2005, Jotto

We want to get to the picture on the left, though the buttons to indicate letters in/out aren't necessarily part of the UI.

We are starting with code that displays the GUI on the right. There is one box for entering text (there should be more) and the UI for selecting letters that are in/out is different.

In class we talked about the UIs and what would be better, e.g., the button panel at the bottom on the left, or a spinner-like field such as the one on the right. See below the screen-shots for more details.

Goal? Starting
* *spin*

You should also allow the user to select the degree of difficulty of the game, e.g., how many guesses before the game is over (easy, medium, hard, for example).

In Class, March 23

As a start toward creating the buttons on the bottom-left above, we wrote the code below in class. It was meant to illustrate anonymous inner-classes, processing events, and the GridLayout class. public static class KeyboardPanel extends JPanel{ public KeyboardPanel(){ this.setLayout(new GridLayout(6,5)); for(char i = 'A'; i <= 'Z'; i++){ final JButton b = new JButton(""+i); b.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { Color c = b.getForeground(); if (c == Color.GRAY){ //b.setBackground(Color.RED); b.setForeground(Color.RED); } else { // b.setBackground(Color.GRAY); b.setForeground(Color.GRAY); } } }); this.add(b); } } } Using this code, and the Jotto assignment you can check out from Eclipse (or access source here) you are to work by yourself toward creating a working Jotto program similar whose UI is like the one on the left above. It should have several levels (number of incorrect guesses before losing), should have a UI for helping the player manage letters --- this is in, this is out, etc.

For extra credit, write a new program (model and view) based on these so that the computer guesses the user's word. The user would enter the number of correct letters, the computer would guess words. There are several UI issues here, the model is pretty simple: the computer guesses, at random, a word that could be the correct one. Based on the user's response (e.g., 2 letters in common) the computer removes all words that could not be the secret user word from it's temporary dictionary, then repeats. This is pretty simple to code, and will beat humans nearly every time.


Owen L. Astrachan
Last modified: Wed Mar 23 21:23:41 EST 2005