Hey Leute ich bin grade dabei mein erstes Programm zuschreiben welches sich mit einer SQL Datenbank verbindet und dann über Checkboxen die Befehle für die Jeweiligen Tabels gesammelt werden und anschließend erst einmal gespeichert werden bevor ich sie in ein Statement gebe. Durch If kriege ich leider nur den wert welche Checkboxen die ich gewählt habe in der Console ausgegeben.
Java:
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Auswahlfenster implements ActionListener {
JFrame Auswahldatenbank = new JFrame();
JPanel AuswahlCheckBox = new JPanel();
JButton SuchButton = new JButton("Suchen");
JCheckBox checkBoxat1 = new JCheckBox("Attribut 1");
JCheckBox checkBoxat2 = new JCheckBox("Attribut 2");
JCheckBox checkBoxat3 = new JCheckBox("Attribut 3");
JCheckBox checkBoxat4 = new JCheckBox("Attribut 4");
JCheckBox checkBoxat5 = new JCheckBox("Attribut 5");
JCheckBox checkBoxat6 = new JCheckBox("Attribut 6");
JCheckBox checkBoxat7 = new JCheckBox("Attribut 7");
JCheckBox checkBoxat8 = new JCheckBox("Attribut 8");
JCheckBox checkBoxat9 = new JCheckBox("Attribut 9");
JCheckBox checkBoxat10 = new JCheckBox("Attribut 10");
String attribut1 = new String("Attribut 1");
String attribut2 = new String("Attribut 2");
String attribut3 = new String("Attribut 3");
String attribut4 = new String("Attribut 4");
String attribut5 = new String("Attribut 5");
String attribut6 = new String("Attribut 6");
String attribut7 = new String("Attribut 7");
String attribut8 = new String("Attribut 8");
String attribut9 = new String("Attribut 9");
String attribut10 = new String("Attribut 10");
Auswahlfenster(){
JPanel panelNorth = new JPanel();
JPanel panelSouth = new JPanel();
JPanel panelWest = new JPanel();
JPanel panelEast = new JPanel();
panelNorth.setPreferredSize(new Dimension(100,100));
panelSouth.setPreferredSize(new Dimension(100,100));
panelSouth.add(SuchButton);
panelEast.setPreferredSize(new Dimension(50,50));
panelWest.setPreferredSize(new Dimension(50,50));
AuswahlCheckBox.setPreferredSize(new Dimension(100,100));
SuchButton.addActionListener(this);
Auswahldatenbank.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Auswahldatenbank.setLayout(null);
Auswahldatenbank.setSize(500,500);
Auswahldatenbank.setLayout(new BorderLayout());
Auswahldatenbank.setVisible(true);
Auswahldatenbank.add(AuswahlCheckBox,BorderLayout.CENTER);
Auswahldatenbank.add(panelNorth, BorderLayout.NORTH);
Auswahldatenbank.add(panelEast, BorderLayout.EAST);
Auswahldatenbank.add(panelWest, BorderLayout.WEST);
Auswahldatenbank.add(panelSouth, BorderLayout.SOUTH);
AuswahlCheckBox.add(checkBoxat1);
AuswahlCheckBox.add(checkBoxat2);
AuswahlCheckBox.add(checkBoxat3);
AuswahlCheckBox.add(checkBoxat4);
AuswahlCheckBox.add(checkBoxat5);
AuswahlCheckBox.add(checkBoxat6);
AuswahlCheckBox.add(checkBoxat7);
AuswahlCheckBox.add(checkBoxat8);
AuswahlCheckBox.add(checkBoxat9);
AuswahlCheckBox.add(checkBoxat10);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==SuchButton);{
if (checkBoxat1.isSelected()) {
attribut1 = "Tabellen name";// in die Klammer kommt das SQL statement
System.out.println(attribut1);
if (checkBoxat2.isSelected()) {
System.out.println(attribut2);
}
if (checkBoxat3.isSelected()) {
System.out.println(attribut3);
}
if (checkBoxat4.isSelected()) {
System.out.println(attribut4);
}
if (checkBoxat5.isSelected()) {
System.out.println(attribut5);
}
if (checkBoxat6.isSelected()) {
System.out.println(attribut6);
}
if (checkBoxat7.isSelected()) {
System.out.println(attribut7);
}
if (checkBoxat8.isSelected()) {
System.out.println(attribut8);
}
if (checkBoxat9.isSelected()) {
System.out.println(attribut9);
}
if (checkBoxat10.isSelected()) {
System.out.println(attribut10);
}
}
}
}
}