// COMPUERTA OR CON BOTONES import java.awt.event.*; import javax.swing.*; import java.awt.*; public class Logico_OR extends JPanel { JButton OR1, OR2, R_OR; JLabel OR, EQ_OR; Font F = new Font("Arial Bold", Font.BOLD, 30); public Logico_OR() { setLayout( null ); this.setBounds(30, 50, 600, 300); setVisible(true); OR1=new JButton(); OR2=new JButton(); OR=new JLabel("OR"); OR.setFont(F); EQ_OR=new JLabel("="); EQ_OR.setFont(F); R_OR = new JButton(); add(OR1); add(OR2); add(OR); add(EQ_OR); add(R_OR); 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()); } 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); } } }