Logico_AND.java



// COMPUERTA AND CON BOTONES
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;

public class Logico_AND extends JPanel
{
	JButton AND1, AND2, R_AND;
	JLabel AND, EQ_AND;
	Font F = new Font("Arial Bold", Font.BOLD, 30);


	public Logico_AND()
	{
		setLayout( null );
		this.setBounds(30, 50, 600, 300);
		setVisible(true);

		AND1=new JButton();AND2=new JButton();
		AND=new JLabel("AND");AND.setFont(F);
		EQ_AND=new JLabel("=");
		EQ_AND.setFont(F); R_AND = new JButton();


		add(AND1);add(AND2);add(AND);
		add(EQ_AND); add(R_AND);

		AND1.setBackground(Color.green); AND1.setBounds(50, 150, 50, 50);
		AND.setBounds(120, 150, 150, 50);
                AND2.setBackground(Color.green); AND2.setBounds(300, 150, 50, 50);
		EQ_AND.setBounds(400, 150, 50, 50);
                R_AND.setBackground(Color.green); R_AND.setBounds(500, 150, 50, 50);
                AND1.addActionListener(new B1_A());
		AND2.addActionListener(new B2_A());
	}

	protected void processWindowEvent(WindowEvent e)
        { if (e.getID() == WindowEvent.WINDOW_CLOSING) System.exit(0); }

	class B1_A implements ActionListener
        {
                public void actionPerformed(ActionEvent e)
                {
                        if (Color.green == AND1.getBackground())
                                AND1.setBackground(Color.red);
                        else AND1.setBackground(Color.green);
			if (AND1.getBackground() != AND2.getBackground())
                                R_AND.setBackground(Color.red);
                        if (AND1.getBackground()==Color.green &&
                                AND2.getBackground()==Color.green)
                                R_AND.setBackground(Color.green);
                }
        }

	class B2_A implements ActionListener
        {
                public void actionPerformed(ActionEvent e)
                {
                        if (Color.green == AND2.getBackground())
                                AND2.setBackground(Color.red);
                        else AND2.setBackground(Color.green);

			if (AND1.getBackground() != AND2.getBackground())
                                R_AND.setBackground(Color.red);
                        if (AND1.getBackground()==Color.green &&
                                AND2.getBackground()==Color.green)
                                R_AND.setBackground(Color.green);
                }
        }


}