Baal
Tank
- Joined
- Sep 22, 2003
- Messages
- 4,357
- Reaction score
- 1
:dozey:
So anyways, I have been assigned to create a basic D&D game for my Java class.
I have four classes set up: An armor class, weapon class, character class, and the form: NewJFrame
I am attempting to pass a variable from the form class (selectedIndex of a combo box) so that I can pick weapons/armor from an armory and then have the code execute (battle take place) based on the weapons/armor selected.
I have basically everything set up already, except for the ability to pass variables from the form to the armor/weapon classes.
There is my form, just to get an idea of what I'm getting at. Basically, when I click the "enter battle" button, I need to pass variables from the form class to the armor/weapon classes
Some of my code:
This is the action event for my combo box. So, for example, I would like to be able to take the setSelArmor variable and pass it, but I get one of two errors:
Then if I try to use a set/get method it says I cannot reference a non-static variable from a static context
So anyways, I have been assigned to create a basic D&D game for my Java class.
I have four classes set up: An armor class, weapon class, character class, and the form: NewJFrame
I am attempting to pass a variable from the form class (selectedIndex of a combo box) so that I can pick weapons/armor from an armory and then have the code execute (battle take place) based on the weapons/armor selected.
I have basically everything set up already, except for the ability to pass variables from the form to the armor/weapon classes.
There is my form, just to get an idea of what I'm getting at. Basically, when I click the "enter battle" button, I need to pass variables from the form class to the armor/weapon classes
Some of my code:
Code:
private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int setSelArmor = 0;
setSelArmor = jComboBox2.getSelectedIndex();
if (setSelArmor == 1 || setSelArmor == 2) {
jComboBox1.setEnabled(true);
}
else {
jComboBox1.setEnabled(false);
jComboBox1.setSelectedIndex(1);
}
}
This is the action event for my combo box. So, for example, I would like to be able to take the setSelArmor variable and pass it, but I get one of two errors:
Code:
public class armor extends NewJFrame {
int calcArm(char cType){
int armPicked = NewJFrame.setSelArmor;
}
}
//results in "cannot find symbol" (cannot find the variable)
Then if I try to use a set/get method it says I cannot reference a non-static variable from a static context