First off, I want to make it very clear that I *do not* know how to program in Java. It is a language I would like to learn, along with the C's (C, C++,C#), Python & Perl.
But I have noticed a couple of things.
Main table have 2 fields (VID and
Name) - VID is the primary key
"Name" is a reserved word in Access and shouldn't be used for object names (as in field names).
You have these 3 colors:
jCheckBox1.setText("Red");
jCheckBox2.setText("Pink");
jCheckBox3.setText("Orange");
And lets set the value of
VID = 52
Name = "Test"
Here is a portion of your code:
(Comments in line)
Code:
private void
jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int VID=Integer.parseInt(jTextField1.getText());
//variable VID value is now 52
String Name=jTextField2.getText();
//variable Name value is now "Test"
String Color = null;
if (jCheckBox1.isSelected()){
Color=String.valueOf(jCheckBox1.getText());
// variable COLOR value is now "RED"
}
if (jCheckBox2.isSelected()){
Color=String.valueOf(jCheckBox2.getText());
// variable COLOR value is now "Pink"
}
if (jCheckBox3.isSelected()){
Color=String.valueOf(jCheckBox3.getText());
// variable COLOR value is now "Orange"
}
Keytest d=new Keytest();
d.openDb();
//
// at this point VID = 52, Name = "Test" and Color = "Orange"
// as long as three colors are selected,
// Color will always equal "Orange"
//
d.insert1(VID,Name);
d.insert2(VID,Color);
d.closeDb();
}
You could use 3 variables for the color: Color1, Color2, Color3
then use
Code:
if (jCheckBox1.isSelected()){
Color1 =String.valueOf(jCheckBox1.getText());
// variable COLOR value is now "RED"
}
if (jCheckBox2.isSelected()){
Color2 =String.valueOf(jCheckBox2.getText());
// variable COLOR value is now "Pink"
}
if (jCheckBox3.isSelected()){
Color3=String.valueOf(jCheckBox3.getText());
// variable COLOR value is now "Orange"
}
d.openDb();
d.insert1(VID,Name);
if (jCheckBox1.isSelected()){
d.insert2(VID,Color1);
}
if (jCheckBox2.isSelected()){
d.insert2(VID,Color2);
}
if (jCheckBox3.isSelected()){
d.insert2(VID,Color3);
}
d.closeDb();
or some kind of looping ..... wish I knew Java