Documentation for Logic Gates applet

 

Gates : class

Main class for the applet.

Set up for applet background.

The background color is set and a canvas object is created by setting its size and adding it to the applet.

No return value.

 

Canvas1 : class

Checks whether the mouse pointer is on any of the input switches.

This method iteratively scans each input switch and sees if the mouse pointer is on that switch. If the mouse is found to be on a switch, the method returns.

Inputs : x and y coordinates of mouse position.

Returns : Switch number (0 onwards) if mouse is on a switch

'20' if mouse is not on a switch.

 

Gate : class

Represents the gate completely.

Indicates the type of gate (0 - and, 1 - or, 2 - xor, 3 - nand, 4 - nor, 5 - xnor, 6 - not)

Indicates how many inputs the gate has.

Stores the inputs for the gate (either 0 or 1).

Stores the output of the gate.

Draws the gate on screen alongwith input and output switches (by calls to the next 2 methods).

A switch structure is used which checks the type of the gate and depending on the type the gate is drawn using the Graphics object.

Takes as input the Graphics object created in the Canvas1 class.

Draws the input switch.

The input switch is drawn at the appropriate location using the value of ‘input’. The color of the switch is selected from an array ‘colors’ which stores the colors red and green. Depending on the value of the input the color is selected from the array.

Inputs : The Graphics object created in the Canvas1 class.

The input switch to be drawn (1 or 2)

Draws the output switch.

The input switch is drawn at the appropriate location. The color of the switch is selected from an array ‘colors’ which stores the colors red and green. Depending on the value of ‘output’ the color is selected from the array.

Takes as input the Graphics object.

Computes the output of the gate for the inputs at that instant.

This method uses a switch structure which checks the type of the gate and depending on this type it applies the appropriate logic rule for that gate to compute the output for the particular inputs.

Draws the truth table for all 2 input gates.

Checks the type of the gate and draws the truth table by filling it with values which are provided.

Takes as input the Graphics object.

Draws the truth table for the NOT gate.

Takes as input the Graphics object.