Hi all,
I hope someone can help me out. I've had to do some code in java, a language I'm very much unfamiliarly with so please excuse my incorrect use of terms. The basic outline of my problem is I create a class object as a local within a swing button function it works fine. If I create it as a global ( with I think I need to do ) within main, then prototype it with the other swing objects at the bottom of the file when it is called it causes a host of problems. I think the easiest way is to show it. So I declare the class at the top of my code
Code:
class GameTextData
{
private String Namestr;
public void setgamenamestring(String st)
{
Namestr = st;
}
}
I then make the object with in the main loop
Code:
public static void main(String args[]) {
GameTextData MainVariableList = new GameTextData();
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new GameDevelopment().setVisible(true);
}
});
}
I then try to call it from my button handler (which netbeans has placed above main) as follows
Code:
private void jsetupdoneButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//what to do with game name entry
if( jGameNameField.getText().equals("") )
{
System.out.println("error please enter game name");
return;
}
else System.out.println(jGameNameField.getText());
MainVariableList.setgamenamestring( jGameNameField.getText() );
//test it
System.out.println( MainVariableList.Namestr );
}
this reports an error of
Code:
cannot find symbol
symbol : variable MainVariableList
location: class GameDevelopment
MainVariableList.setgamenamestring( jGameNameField.getText() );
I can see that netbeans shows prototypes at the bottom of the main file, so I try to copy this and prototype my variable there, if I do this it give a private access for the variable in the class,
Code:
Namestr has private access in GameTextData
System.out.println( MainVariableList.Namestr );
if I take off private for my string it will compile however when I call the button function it gives a dozen errors.
Can anyone advise? Thanks in advace