Categories: All - nodes - logic

by Ethan Chen 1 year ago

127

TraditionalGates

The text outlines a structure for a graphical user interface component used in creating and managing logic gate circuits. The primary class, Component, extends JLabel and implements multiple listener interfaces, handling mouse actions for drawing lines, obtaining coordinates, and managing gate interactions.

TraditionalGates

From the top of the circuit: the output Calls upon each other until it reaches an input gate

First

abstract class Component extends JLabel implements MouseListener, MouseMotionListener

abstract class Connector

class Output extends Connector
class Input extends Connector

class Connection

class DrawPanel extends JPanel

public void addElement(String element)

public void addConnection(int indexInput, int indexOutput)

public boolean updateCircuit()

public boolean oneInput(int pos)

for the NOT gate, since it only has 1 input node

public boolean twoInput(int pos, String type)

For all the other gates (they all have 2 input and 1 output node).

updates the circuit via recursive method.

adds a connection in the 2D array

2D array for the logic. This is what sets the output gate to either green or red once measured.

Is called to spawn the gates. Depending on (int) gateChoice, it will spawn a logic gate or input/output gate. It makes a fully functional gate by calling previous functions and combining them together.

Draws lines between output and input nodes.

specific rules for input gate, such as maximum number of output connections.

specific rules for output gate, such as redrawing border color to green/red and calculating the input value
Basic rules and functions for the gates

Input gate sets variable (int) output = 1. Also has most features like a regular gate.

Output gate starts with default border color red. Also has most features like a regular gate.

States what a gate is (borders, colors, name, input/output nodes, spawn coordinates, input values)

- Mouse Listener - line drawer (connects nodes) - coordinate getter - logic for the showInputs and showOutputs - drag function for the gates

public class CircuitDesigner

Measure

repaints border color of the output gate to red/green depending on overallOutput.

JButton for all the gates

Calls addNewComponent() and sets (int) gateChoice to a number (1-9) (which makes the next click spawn the correct gate).
void addNewComponent()

prompt.setText("Click to add component");

addingComponent = true; This allows the next click to spawn a gate according to the right number (1-9) set by int gateChoice.

JButton newConnectionButton

Calls addNewConnection()
prompt.setText("Click an output to connect...");

selectingOutput = true; showInputs = false; This makes the blue triangles invisible and forces the user to click a red triangle then a blue one. This will then create a line between them.

- ArrayLists - JLabels - JFrames - booleans - ints - components - strings - drawPanels

java.awt.* java.util.* java.swing.*