Timmy
Timmy

Reputation: 21

Create a new ArrayList in Netbeans

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:(

Upvotes: 0

Views: 6921

Answers (1)

Rahul Bhawar
Rahul Bhawar

Reputation: 450

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 
}

}

Upvotes: 1

Related Questions