/** @author Scott Marshall @author University of Glasgow, MSc IT Project 2001 @author Building an OnLine Course in Computing Fundamentals */ package ukacgla_TruthTable; import ukacgla_ATT.*; import javax.swing.*; import javax.swing.border.Border; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; /** Provides specifics for drawing this circuit (ie co ordinates and joining lines) The generic methods for drawing specific types of gates are in parent class. */ public class Ex01_Graphics extends circuitGraphics{ public Ex01_Graphics(frameMaker g, TTRandom r){ super(g,r); } /* Gate 1 to be drawn at point 50,35 Gate 2 to be drawn at point 50,165 Gate 3 to be drawn at point 300,100 */ public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; //Instantiate graphics object switch (random.getRandom1()) { case 0: draw2LinesA(g2); drawOtherLines(g2); drawAndGate(g2,50,35); break; case 1: draw2LinesA(g2); drawOtherLines(g2); drawOrGate(g2,50,35); break; case 2: drawOneLineA(g2); drawOtherLines(g2); drawInverter(g2,50,35); break; case 3: draw2LinesA(g2); drawOtherLines(g2); drawNandGate(g2,50,35); break; case 4: draw2LinesA(g2); drawOtherLines(g2); drawXOrGate(g2,50,35); break; } switch (random.getRandom2()) { case 0: draw2LinesB(g2); drawOtherLines(g2); drawAndGate(g2,50,165); break; case 1: draw2LinesB(g2); drawOtherLines(g2); drawOrGate(g2,50,165); break; case 2: drawOneLineB(g2);drawOtherLines(g2); drawInverter(g2,50,165); break; case 3: draw2LinesB(g2); drawOtherLines(g2); drawNandGate(g2,50,165); break; case 4: draw2LinesB(g2); drawOtherLines(g2); drawXOrGate(g2,50,165); break; } /* Gate 3 MUST be a 2 input gate Case 2 deliberately breaks randomness. Result is gate 3 is twice as likely to be an XOr gate. An Inverter cannot occupy postition 3. */ switch (random.getRandom3()) { case 0: drawAndGate(g2,300,100); break; case 1: drawOrGate(g2,300,100); break; case 2: drawXOrGate(g2,300,100); break; // deliberate breaking of randomness case 3: drawNandGate(g2,300,100); break; case 4: drawXOrGate(g2,300,100); break; } } /*-------------------------------------------- Drawing coordinates for full circuit of three separate 2 input gates. a---b e|------f c---d | | g----------h i|----------j q----------r | k---l | o|-------p m---n a = 10,45 b = 60,45 c = 10,55 d = 60,55 e = 60,50 f = 210,50 g = 210,105 h = 310,105 i = 310,115 j = 450,115 k = 10,175 l = 50,175 m = 10,185 n = 50,185 o = 50,180 p = 210,180 q = 210,125 r = 310,125 -------------------------------------------*/ private void draw2LinesA(Graphics g){ g.drawLine(10,45,60,45);//a to b g.drawLine(10,55,60,55);//c to d g.drawLine(60,50,210,50);//e to f g.drawString("x1",15,40); g.drawString("y1",15,70); } private void draw2LinesB(Graphics g){ g.drawLine(10,175,60,175);//k to l g.drawLine(10,185,60,185); //m to n g.drawLine(60,180,210,180); //o to p g.drawString("a1",15,165); g.drawString("b1",15,200); } /*-------------------------------------------- Drawing coordinates for when Gates 1 or 2 are a single input gate. A-----------B   C----------D E----------F I----------J  G-----------H A = 10,50 B = 210,50 C = 210,105 D = 310,105 E = 310,115 F = 450,115 G = 10,180 H = 210,180 I = 210,125 J = 310,125 --------------------------------------------*/ private void drawOneLineA(Graphics g){ g.drawLine(10,50,210,50);//a to b g.drawString("x",15,40); } private void drawOneLineB(Graphics g){ g.drawLine(10,180,210,180);//g to h g.drawString("a",15,195); } private void drawOtherLines(Graphics g) { g.drawLine(210,50,210,105); //b to c g.drawLine(210,105,310,105);//c to d g.drawLine(310,115,450,115);//e to f g.drawLine(210,180,210,125);//h to i g.drawLine(210,125,310,125);//i to j g.drawString("m",130,40); g.drawString("n",130,200); g.drawString("o",380,105); } }//ends class