por Ethan Chen 1 ano atrás
127
Mais informações
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.
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.
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.