0

I'm new to programming in Netbeans, so keep it as simple as possible, please.

So, right now I have 3 java files in the same project: mainframe.java, edit.java and add.java.

In the mainframe-window you have 2 buttons which get you to the edit and add-window. In the add-window you get to enter a text in a text field and then press a button to add it into an ArrayList, I did this:

public static void main(String args[]) {

    List<String> Hey = new ArrayList<String>();
}

And the Button:

private void btnFortsattActionPerformed(java.awt.event.ActionEvent evt) 

{ 
    //The variable name of the text field is "txfCreate"

    String text = txfCreate.getText();
    Hey.add(text);  //The problem here is that Netbeans cannot find "Hey" symbol 

} 

Next, in the edit-window, I have a JList to show the content of the ArrayList. I have no idea know how to code it:(

3
  • 3
    Start by taking a look at Variable Scope Commented Jan 27, 2016 at 11:40
  • 2
    there's nothing related to netbeans in this question. Like doing the same thing in eclipse would work... Commented Jan 27, 2016 at 11:46
  • Try to read about Variables Scopes in Java. You will find an aswer in 5 minutes. Commented Jan 27, 2016 at 13:11

1 Answer 1

1
public class My {

List<String> Hey;

public static void main(String args[]) {
    Hey = new ArrayList<String>();
}

private void btnFortsattActionPerformed(java.awt.event.ActionEvent evt) {
    //The variable name of the text field is "txfCreate"

    String text = txfCreate.getText();
    Hey.add(text);  //The problem here is that Netbeans cannot find "Hey" symbol 
}

}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.