public class CircuitDesigner
java.awt.*
java.util.*
java.swing.*
- ArrayLists
- JLabels
- JFrames
- booleans
- ints
- components
- strings
- drawPanels
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.
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.
Measure
repaints border color of the
output gate to red/green
depending on overallOutput.
abstract class Component extends JLabel implements MouseListener, MouseMotionListener
- Mouse Listener
- line drawer (connects nodes)
- coordinate getter
- logic for the showInputs and showOutputs
- drag function for the gates
States what a gate is
(borders, colors, name,
input/output nodes, spawn
coordinates, input values)
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.
abstract class Connector
Basic rules and functions for the gates
class Output extends Connector
specific rules for output gate,
such as redrawing border color
to green/red and calculating the
input value
class Input extends Connector
specific rules for input gate,
such as maximum number of
output connections.
class Connection
Draws lines between
output and input nodes.
class DrawPanel extends JPanel
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.
public void addElement(String element)
2D array for the logic.
This is what sets the
output gate to either
green or red once measured.
public void addConnection(int indexInput, int indexOutput)
adds a connection in
the 2D array
public boolean updateCircuit()
updates the circuit
via recursive method.
public boolean oneInput(int pos)
public boolean twoInput(int pos, String type)
For all the other gates
(they all have 2 input
and 1 output node).
for the NOT gate,
since it only has 1
input node