Created
January 23, 2016 18:13
-
-
Save kishida/24813c9ac1f683454ac5 to your computer and use it in GitHub Desktop.
Logical operation playground.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Author
kishida
commented
Jan 23, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment