Skip to content
Snippets Groups Projects
Commit c153a494 authored by Uli Bähr's avatar Uli Bähr
Browse files

neue Klasse ChkBoxPanel

parent dcfe6fe1
No related branches found
No related tags found
No related merge requests found
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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment