[Image]

Crypto

Encrypts a message by adding extra random letters.  The user must pass an ID check (ID number and Password) before using the program.

AWT App Structure

This is a complete (but highly simplified) AWT application.  It uses a JOptionPane for input and output dialogs - this is actually a Swing component, but is a separate class and is not "added" to the interface Frame.  


Overall Structure

The program (class) has 6sections:

  1. main
    Starts the program by making a copy of the class (instantiating), and making it visible
  2. components
    The components are created outside any methods.  Then they are usable (accessible) throughout the program.
  3. constructor
    The constructor adds the components to the window (Container), and connects their actions to the actionPerformed method.
  4. actionPerformed
    Responds to buttons being clicked (handles events).  Each button (JButton) normally executes one of the methods below.
  5. further methods
    As many methods as the program needs.  In this case, it needs four methods:  encrypt, decrypt, checkPassword, showHelp.  It is possible to do all the programming inside the actionPerformed method, but this makes a very messy program.
  6. IBIO
    Simplified input and output dialogs for IB standard data types:
       String , int , double , byte , long , char , boolean

    This is the GUI version, so each input and output uses a pop-up dialog box.

This overall structure is not a requirement - in fact, this is not really the "preferred" approach at all. The actionPerformed event handler is an "old-fashioned" approach.  But this structure is recommended for beginners as it is straightforward.  It also encourages a sensible "top-down" design strategy.


Important Commands

int id = inputInt("ID Number");
IBIO input command for inputting an integer number.  If the user does not type a proper number, inputInt catches the error and returns 0 (zero). There are input commands for various data types -
  inputDouble, inputString, inputChar, inputByte, inputLong, inputBoolean

output("ID check failed");
IBIO provides output commands for all the IB standard data types.  The methods simply convert the type to a String and then output the String.

public boolean checkPassword()
..return false;
In Java, a function is a method which can return an answer.  The return type is written before the function (method) name. The return command terminates the method and returns the value specified.

(char)(int)(random decimal)
The types in parentheses change (cast) a value from one type to another.  This example takes random decimal, casts it to an int, then casts that result to a char.

Double.valueOf(String).doubleValue();
Changes a String into a double value.  If this fails - e.g. "25 cm" will cause an error - the error needs to be handled by a try..catch.. construct, as shown in the inputDouble method.


Comments

This AWT program shows a structure which is usable for IB programming projects.  The IBIO input/output commands will be used in algorithm questions on the IB exams, so students should become familiar with them (use them, not memorize the methods' contents).  The syllabus provides text-mode versions of these methods.  Although GUI interfaces are not required, most students will probably want to use GUI apps for their programming work.

It is a bit silly to start a program with a blank screen and type the import commands, the main method, and the IBIO methods from scratch.  Teachers will probably create a standard template similar to this program.  In many IDEs (including JCreator) it is possible to store templates that are easily reused.

IB students are encouraged to use the IBIO input and output commands in the beginning, to make it easy to get started writing Java programs.  Later, they may wish to design their own I/O dialogs, or stick to component based I/O using get and set commands in TextFields.