How to get methods to see variables in other methods
I am working on my class assignment and I am still having problems understanding how to get variable data to flow from one method to another method. For a sample I am just trying to make a press of a button change a text box to be equal to the data stored in an array[0]. I do not understand how to get the method with the button to be able to see the data in the method with the array. What do I need to do to be able to use the data in the array in the button method? I keep getting an error " Can't find symbol: variable itemNum"
//Array
public void storedata() {
String[] itemNum = {"1","2"};
}
//VCR FIRST BUTTON
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String temp = itemNum[0];
jTextField1.setText(temp);
}
Still not quite understanding.
Thanks for the quick replys, but I just can't grasp this what seems to be simple task. Instead of setting the textbox to a variable value when the button is pressed I tried a string value and the program worked. Everything I do to try and get the array value or any variable value to update the textbox I run into variable not found errors. Any additional help would be greatly appreciated as I am very new to Java and if I can get past this I will be able to complete my program with ease. Here is a better example of how my code is actually layed out.
public class MYGUI extends javax.swing.JFrame {
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String temp = "5";
jTextField1.setText(temp);
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String temp = "5";
jTextField1.setText(temp);
}
class storedata {
String[] itemNum = {"1","2"};
}
}