Skip to content

Instantly share code, notes, and snippets.

@kishida
Created January 23, 2016 18:13
Show Gist options
  • Save kishida/24813c9ac1f683454ac5 to your computer and use it in GitHub Desktop.
Save kishida/24813c9ac1f683454ac5 to your computer and use it in GitHub Desktop.
Logical operation playground.
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.util.stream.Stream;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
* @author naoki
*/
public class LogicalOperation {
public static void main(String[] args) {
JFrame f = new JFrame("Logical Op");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(200, 200);
f.setLayout(new GridLayout(4, 1));
JPanel panel = new JPanel(new FlowLayout());
JCheckBox chkLeft = new JCheckBox("Left");
JCheckBox chkRight = new JCheckBox("right");
Stream.of(chkLeft, chkRight).forEach(panel::add);
JCheckBox chkAnd = new JCheckBox("And");
JCheckBox chkOr = new JCheckBox("Or");
JCheckBox chkXor = new JCheckBox("Xor");
Stream.of(panel, chkAnd, chkOr, chkXor).forEach(f::add);
ActionListener al = ae -> {
boolean left = chkLeft.isSelected();
boolean right = chkRight.isSelected();
chkAnd.setSelected(left & right);
chkOr .setSelected(left | right);
chkXor.setSelected(left ^ right);
};
Stream.of(chkLeft, chkRight).forEach(c -> c.addActionListener(al));
f.setVisible(true);
}
}
@kishida
Copy link
Author

kishida commented Jan 23, 2016

screen shot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment