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 8883545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:50:16+00:00 2026-06-14T20:50:16+00:00

How can I do such a thing? String N = jTextField0.getText(); MyClass (N) =

  • 0

How can I do such a thing?

String N = jTextField0.getText();
MyClass (N) = new Myclass();

Is it even possibe?
Or as my question’s explains, how can I just make a method to create a new object of my specified class just with a different name each time I call it.
I really searched everywhere with no luck.
Thanks in Advance

P.S.
I wish you guys can excuse me for not being clear enough, Just to say it as it is, I made a textfield to get the name of someone who wants to make an account, and I made a class named “Customer”. and a button named “Add”. Now I want every time “Add” is clicked, compiler take what is in my textfield and make an object of the class “Customer” named with what it took from the textfield

It was too hard to read it in comments so I updated my question again, so sorry.
I’m stuck so bad. I suppose my problem is that I didn’t “understand” what you did and only tried to copy it. This is what I wrote:

private void AddB0MouseClicked(java.awt.event.MouseEvent evt) {
    String name = NameT0.getText();
    Customer instance = new Customer(Name);
    Customer.customers.add(instance);

and this is my Customer class:

public class Customer{
String name;
public Customer(String name){
this.name = name;
}
public String getName(){
    return name;
    }
static ArrayList<Customer> customers = new ArrayList<Customer>();
  • 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-14T20:50:18+00:00Added an answer on June 14, 2026 at 8:50 pm

    I’m not entirely sure what you mean by…

    how can I just make a method to create a new object of my specified
    class just with a different name each time I call it

    …but if I’m interpreting you correctly, I believe what you’re trying to do as make MyClass accept a constructor parameter. You can do:

    public class MyClass {
        private String name;
    
        public MyClass(String name) {
            this.name = name;
        }
    
        public String getName() {
            return name;
        }
    }
    

    Then to create a new instance of MyClass, do:

    String name = jTextField0.getText();
    MyClass instance = new MyClass(name);
    instance.getName(); // returns the name it was given
    

    EDIT

    Since you’ve added clarifications in the comments since I first answered this question, I thought I would update the answer to portray more of the functionality that you’re looking for.

    To keep track of the MyClass instances, you can add them to an ArrayList. ArrayList objects can be instantiated as follows:

    ArrayList<MyClass> customers = new ArrayList<MyClass>();
    

    Then for each MyClass instance you wish to add, do the following:

    customers.add(instance);
    

    Note that the ArrayList should not be reinstantiated for each instance that you wish to add; you should only instantiate the ArrayList once.

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

Sidebar

Related Questions

how can i do such thing in model or controller? <%= Url.Action(Home); %>
Is there such a thing? I know that I can hook my function on
Can I ship my application with compiled templates? I there such a thing at
How can I simply disable a TkInter Listbox? It seems such a straightforward thing
If we use NSTrackingArea for some specified region then we can implement such method
I can do such thing in python: l = ['one', 'two', 'three'] if 'some
Is there such a thing as an x86 assembler that I can call through
I think I can use any object to be synchronized as block such as:
As we can execute such executables in two ways, such as sudo mono test.exe,
As we all know,we can use such api as LockWorkStation() in user32.dll to lock

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.