Las compuertas logicas actuan de la siguiente manera:
OR : suma las 2 entradas y entrega 1
AND : multiplica las 2 entradas y entrega 1
NOT : niega la variable entrante
las tablas de verdad no creo sean necesarias agregarlas...
Bueno he aqui los codigos
Código HTML:
]Ver original
import java.applet.Applet; import java.awt.*; public class CompuertaOR extends Applet { Button btn0; Button btn1; Button btn2; Button btn3; Button btnr; Button btnl; double var1; double var2; double var3; String svar1; String svar2; String svar3; String svarl; TextField tex1; TextField tex2; TextField tex3; public CompuertaOR() { } public boolean action(Event event,Object obj) { if(event.target == btn0) { var1 = 0.0D; svar1 = "A = 0"; tex1.setText(svar1); return true; } if(event.target == btn1) { var1 = 1.0D; svar1 = "A = 1"; tex1.setText(svar1); return true; } if(event.target == btn2) { var2 = 0.0D; svar2 = "B = 0"; tex2.setText(svar2); return true; } if(event.target == btn3) { var2 = 1.0D; svar2 = "B = 1"; tex2.setText(svar2); return true; } if(event.target == btnl) { svarl = " "; tex1.setText(svarl); tex2.setText(svarl); tex3.setText(svarl); return true; } if(event.target == btnr){ if(var1==0 && var2==0) { var3 = 0.0D; svar3 = "Z = 0"; tex3.setText(svar3); return true; } } if(var1==1 || var2==1) { var3 = 1.0D; svar3 = "Z = 1"; tex3.setText(svar3); return true; } else return false; } public void init() { btn0 = new Button("0"); btn1 = new Button("1"); btn2 = new Button("0"); btn3 = new Button("1"); btnr = new Button("Salida"); btnl = new Button("Limpiar"); tex1 = new TextField(5); add(tex1); add(btn0); add(btn1); tex2 = new TextField(5); add(tex2); add(btn2); add(btn3); tex3 = new TextField(5); add(tex3); add(btnr); add(btnl); setBackground(Color.black); svar1 = "A = 0"; svar2 = "B = 0"; tex1.setText(svar1); tex2.setText(svar2); } public void paint(Graphics g) { g.setColor(new Color(100,255,140)); g.drawLine(220,80,230,105); g.drawLine(220,130,230,105); g.drawLine(200,95,220,95); g.drawLine(200,115,220,115); g.drawArc(170,80,100,50,0,90); g.drawArc(170,80,100,50,270,90); g.drawString("A",190,98); g.drawString("B",190,120); g.drawString("Z",295,110); g.drawLine(270,105,290,105); g.drawString("Compuerta Logica OR (2 entradas)",145,170); } }
Código HTML:
Ver original
import java.applet.Applet; import java.awt.*; public class CompuertaAND extends Applet { Button btn0; Button btn1; Button btn2; Button btn3; Button btnr; Button btnl; double var1; double var2; double var3; String svar1; String svar2; String svar3; String svarl; TextField tex1; TextField tex2; TextField tex3; public CompuertaAND() { } public boolean action(Event event,Object obj) { if(event.target == btn0) { var1 = 0.0D; svar1 = "A = 0"; tex1.setText(svar1); return true; } if(event.target == btn1) { var1 = 1.0D; svar1 = "A = 1"; tex1.setText(svar1); return true; } if(event.target == btn2) { var2 = 0.0D; svar2 = "B = 0"; tex2.setText(svar2); return true; } if(event.target == btn3) { var2 = 1.0D; svar2 = "B = 1"; tex2.setText(svar2); return true; } if(event.target == btnl) { svarl = " "; tex1.setText(svarl); tex2.setText(svarl); tex3.setText(svarl); return true; } if(event.target == btnr){ if(var1==1 && var2==1) { var3 = 1.0D; svar3 = "Z = 1"; tex3.setText(svar3); return true; } } if(var1==0 || var2==0) { var3 = 0.0D; svar3 = "Z = 0"; tex3.setText(svar3); return true; } else return false; } public void init() { btn0 = new Button("0"); btn1 = new Button("1"); btn2 = new Button("0"); btn3 = new Button("1"); btnr = new Button("Salida"); btnl = new Button("Limpiar"); tex1 = new TextField(5); add(tex1); add(btn0); add(btn1); tex2 = new TextField(5); add(tex2); add(btn2); add(btn3); tex3 = new TextField(5); add(tex3); add(btnr); add(btnl); setBackground(Color.black); svar1 = "A = 0"; svar2 = "B = 0"; tex1.setText(svar1); tex2.setText(svar2); } public void paint(Graphics g) { g.setColor(new Color(100,255,140)); g.drawLine(220,80,220,130); g.drawLine(220,80,247,80); g.drawLine(220,130,247,130); g.drawLine(200,95,220,95); g.drawLine(200,115,220,115); g.drawArc(220,80,50,50,0,90); g.drawArc(220,80,50,50,270,90); g.drawString("A",190,98); g.drawString("B",190,120); g.drawString("Z",295,110); g.drawLine(270,105,290,105); g.drawString("Compuerta Logica AND (2 entradas)",145,170); } }
Código HTML:
Ver original
import java.applet.Applet; import java.awt.*; public class CompuertaNOT extends Applet { Button btn0; Button btn1; Button btnr; Button btnl; double var1; double var3; String svar1; String svar3; String svarl; TextField tex1; TextField tex2; public CompuertaNOT() { } public boolean action(Event event,Object obj) { if(event.target == btn0) { var1 = 0.0D; svar1 = "A = 0"; tex1.setText(svar1); return true; } if(event.target == btn1) { var1 = 1.0D; svar1 = "A = 1"; tex1.setText(svar1); return true; } if(event.target == btnl) { svarl = " "; tex1.setText(svarl); tex2.setText(svarl); return true; } if(event.target == btnr){ if(var1==0) { var3 = 1.0D; svar3 = "Z = 1"; tex2.setText(svar3); return true; } } if(var1==1) { var3 = 0.0D; svar3 = "Z = 0"; tex2.setText(svar3); return true; } else return false; } public void init() { btn0 = new Button("0"); btn1 = new Button("1"); btnr = new Button("Salida"); btnl = new Button("Limpiar"); tex1 = new TextField(5); add(tex1); add(btn0); add(btn1); tex2 = new TextField(5); add(tex2); add(btnr); add(btnl); setBackground(Color.black); svar1 = "A = 0"; tex1.setText(svar1); } public void paint(Graphics g) { g.setColor(new Color(100,255,140)); g.drawLine(220,85,220,125); g.drawLine(220,85,270,105); g.drawLine(220,125,270,105); g.drawString("A",185,110); g.drawLine(200,105,220,105); g.drawString("Z",295,110); g.drawLine(280,105,290,105); g.drawOval(270,100,10,10); g.drawString("Compuerta Logica NOT",180,170); } }
Bueno eso seria, porfavor, diganme si es correcto este lugar para subir mis aportes! cualquier comentario es una critica constructiva! y espero les sea util