Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9260367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:52:26+00:00 2026-06-18T12:52:26+00:00

I am writing a Java (Swing) application and I’m trying to store stuff in

  • 0

I am writing a Java (Swing) application and I’m trying to store stuff in an ArrayList.
My plan is to first instantiate a class, set some variables in that class and then add that class to an ArrayList.

So I have this class:

public class CollectionClass {

private ArrayList<OwnerClass> owners;

public CollectionClass() {

    owners = new ArrayList<OwnerClass>();

}


public void AddOwner(OwnerClass oc) {
    owners.add(oc);
}
 }

And this class:

public class OwnerClass {
public int id = 0;
public String name = "";
public String employeeNr="";
 }

Now in my dialog I have this:

CollectionClass myCC;

public InvoerNewOwner(CollectionClass cc) {

            myCC = cc;
        btSave.setActionListener(new ActionListener() {
        OwnerClass oc = new OwnerClass();

        oc.name = txtOwner.getText();               <<<
        oc.employeeNr = txtEmployeeNr.getText();    <<<

        myCC.addOwner(oc);                            <<<

    });

I get an error on the 3 lines marked with <<<. The error is “error: <identifier> expected“

What am I doing wrong here?

Is this not a good way to create a collection of objects?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:52:27+00:00Added an answer on June 18, 2026 at 12:52 pm
    btSave.setActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            OwnerClass oc = new OwnerClass();
    
            oc.name = txtOwner.getText();
            oc.employeeNr = txtEmployeeNr.getText();
    
            myCC.addOwner(oc);
        }
    });
    

    You must wrap all of the things you want to do inside an actionPerformed event.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an assignment to create a java Swing application to do some stuff
I am writing a Java swing application which can store resumes (txt,pdf,docx,doc etc.) in
I am writing an application in Java using Swing. I am trying to implement
I'm writing a Java/Swing application with ~30 class my probleme is when i run
I am writing a desktop application written in Swing developed using Java 1.5. Some
I'm writing a Java application with GUI using Swing. One of the GUI components
I am writing an application in java (1.6) using swing. I currently have a
I am writing a mapping application in Java, using Swing for the UI (I've
greetngs, i am trying to learn Java and Swing by writing a simple game
I'm new to programming,now I'm writing Java Swing application. One of the main tasks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.