diff --git a/src/main/java/projekt/enigma/view/ChkBoxPanel.java b/src/main/java/projekt/enigma/view/ChkBoxPanel.java new file mode 100644 index 0000000000000000000000000000000000000000..04b93074aa47a1b13447584a66b580b8c8a2d284 --- /dev/null +++ b/src/main/java/projekt/enigma/view/ChkBoxPanel.java @@ -0,0 +1,74 @@ +package projekt.enigma.view; + +import java.awt.*; +import javax.swing.*; + +public class ChkBoxPanel extends JPanel { + /*private static JPanel panel = new JPanel();*/ + private static JCheckBox[] checkbox; + private static Character[] alphabet;/* = {'A','B','C','D'};*/ + private static int charSize; + + public ChkBoxPanel(Character[] alphabet) { + this.charSize = alphabet.length; + this.alphabet = alphabet; + /*this.setTitle("Vertausche Buchstaben"); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);*/ + this.setSize(30, charSize * 25); + //this.setLocation(getMousePosition()/*.x, getMousePosition().y+this.getHeight()+30*/); + initializeComponents(); + } + + private void initializeComponents() { + this.checkbox = new JCheckBox[charSize]; + GridLayout panelLayout = new GridLayout(); + this.setLayout(panelLayout); + if (!(charSize % 2 == 0)) { + this.setSize(30, (charSize + 1) * 20); + panelLayout.setRows((charSize + 1) / 2); + } else { + this.setSize(30, charSize * 10); + panelLayout.setRows(charSize / 2); + } + panelLayout.setColumns(2); + //panelLayout.setVgap(5); + //panelLayout.setHgap(-5); + + + for (int i = 0; i < charSize; i++) { + checkbox[i] = new JCheckBox(alphabet[i] + ""); + checkbox[i].setSize(15, 20); + checkbox[i].setHorizontalTextPosition(SwingConstants.CENTER); + checkbox[i].setVerticalTextPosition(SwingConstants.TOP); +/* if (!(i%2==0)){ + }*/ + checkbox[i].setMargin(new Insets(0, 20, 0, 20)); + //checkbox[i].setLocation(20, (i + 1) * 30); + this.add(checkbox[i]); + } + /* this.getContentPane().add(panel);*/ + checkbox[0].setSelected(true); + //this.add(panel); + //this.setLocation(100, 100); + this.setVisible(true); + } + + + private int isChecked() { + for (int i = 0; i < charSize; i++) { + if (checkbox[i].isSelected()) { + + // do something... + + } else { + + // do something else... + + } + } + return 0; + } + + +} +