Logico.java



// MUESTRA LAS OPERACIONES AND Y OR CON BOTONES
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;

public class Logico extends JFrame
{
	JButton OR1, OR2, AND1, AND2, R_AND, R_OR;
	JLabel OR, AND, EQ_OR, EQ_AND;
	Font F = new Font("Arial Bold", Font.BOLD, 30);

	public static void main(String ARGS[]) { new Logico(); }

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

		OR1=new JButton();OR2=new JButton();AND1=new JButton();AND2=new JButton();
		OR=new JLabel("OR");AND=new JLabel("AND");OR.setFont(F);AND.setFont(F);
		EQ_OR=new JLabel("=");EQ_AND=new JLabel("=");EQ_OR.setFont(F);
		EQ_AND.setFont(F); R_OR = new JButton(); R_AND = new JButton();


		add(OR1);add(OR2);add(AND1);add(AND2);add(OR);add(AND);
		add(EQ_OR);add(EQ_AND);add(R_OR); add(R_AND);

		OR1.setBackground(Color.green); OR1.setBounds(50, 50, 50, 50);
		OR.setBounds(100, 50, 50, 50);
		OR2.setBackground(Color.green); OR2.setBounds(150, 50, 50, 50);
		EQ_OR.setBounds(200, 50, 50, 50);
		R_OR.setBackground(Color.green); R_OR.setBounds(250, 50, 50, 50);
		OR1.addActionListener(new B1_OR());
		OR2.addActionListener(new B2_OR());

		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_OR implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			if (Color.green == OR1.getBackground())
				OR1.setBackground(Color.red);
			else OR1.setBackground(Color.green);
			if (OR1.getBackground() != OR2.getBackground())
				R_OR.setBackground(Color.green);
			if (OR1.getBackground()==Color.green ||
				OR2.getBackground()==Color.green)
				R_OR.setBackground(Color.green);
			if (OR1.getBackground()==Color.red &&
                                OR2.getBackground()==Color.red)
                                R_OR.setBackground(Color.red);
		}
	}

	class B2_OR implements ActionListener
        {
                public void actionPerformed(ActionEvent e)
                {
                        if (Color.green == OR2.getBackground())
                                OR2.setBackground(Color.red);
                        else OR2.setBackground(Color.green);
			if (OR1.getBackground() != OR2.getBackground())
                                R_OR.setBackground(Color.green);
                        if (OR1.getBackground()==Color.green ||
                                OR2.getBackground()==Color.green)
                                R_OR.setBackground(Color.green);
                        if (OR1.getBackground()==Color.red &&
                                OR2.getBackground()==Color.red)
                                R_OR.setBackground(Color.red);
                }
        }

	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);
                }
        }






}