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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:07:59+00:00 2026-06-01T12:07:59+00:00

I have some classes which are parameterized via their constructor. I need to provide

  • 0

I have some classes which are parameterized via their constructor. I need to provide a graphical user interface that lets the user specify these parameters.
The only thing I can assume about the classes is that there is a constructor (default or with arguments).

[Update]
I have three sets of classes Aimpl, Bimpl, Cimpl. The classes in set Aimple extend class A, classes in Bimpl extend class B, classes in Cimpl extend class C. Instances of A, B and C are used to compute on data. At compile time I don’t know which subclasses are available, so I scan for implementations and add them to the appropriate set. If the end user wants to apply a computation he needs to instantiate it. To instantiate it, he needs to provide proper arguments to the constructor. The end user is a programmer himself and knows of arrays, abstract classes and interfaces. He even knows what reasonable arguments are.

At first only primitive types (or classes that expect primitive types) were expected, so I wrote a solution myself that worked fine.
But now I have to deal with arrays, abstract classes and interfaces. So I’m looking for a library that could simplify the task of providing input fields to the user, extracting the input and creating objects.

If there is no such library, how would I do this myself? For the arrays I could use JTexFields and then parse the input, for abstract classes and interfaces I could scan for extending/implenting classes (using the reflections library) and provide a JComboBox to let the user select.
I am new to programming GUIs so I can’t reliably estimate if my approach is feasible and I don’t want to waste time solving a problem that was solved before.

If information is missing, please feel free to point it out.

  • 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-01T12:08:00+00:00Added an answer on June 1, 2026 at 12:08 pm

    SWoeste is correct reflection is something intended for tasks similar to yours, but it is not very simple to use.

    In fact, your question is not about swing (or GUI at all). You are solving the problem “How to create Object from String.” (or it can be at least reduced to it). If your user is a programmer as you wrote I think that very simple solution for this is to use JSON (my opinion is that it uses very simple and understandable format), my code is for gson 1.6.

    If I have an object, let say FullTimeWorker, that extends Person:

    Person

    package net.betlista.gson;
    
    public class Person {
    
        private String name;
        private String surname; // no setter
    
        public String getName() {
            System.out.println( "Person#getName()" );
            return name;
        }
    
        public void setName( final String name ) {
            this.name = name;
        }
    
    }
    

    FullTimeWorker

    package net.betlista.gson;
    
    public class FullTimeWorker extends Person {
    
        private double salary;
    
    }
    

    Now you can create FullTimeWorker class as

    package net.betlista.gson;
    
    import com.google.gson.Gson;
    import com.google.gson.GsonBuilder;
    
    public class DeserializationTest {
    
        public static void main( final String[] args ) {
            final GsonBuilder gb = new GsonBuilder();
            final Gson gson = gb.create();
            // {
            //    "salary": 1234.5,
            //    "name": "John",
            //    "surname": "Doe",
            // }
            final String in = "{\"salary\":1234.5,\"name\":\"John\",\"surname\":\"Doe\"}";
            final FullTimeWorker w = gson.fromJson( in, FullTimeWorker.class );
        }
    
    }
    

    GUI

    All you need now in GUI is JTextField (or better JTextArea) to insert JSON string, JComboBox for class selection and JButton, so simple.

    It’s clear that your GUI can be almost perfect – it depends only on your imagination, but I’m not sure if there is something simpler than that 😉

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

Sidebar

Related Questions

I have some functionality that I need in all my classes which derive from
I have some classes that all implement the same Java interface, which essentially allows
I have some classes that, for one reason or another, cannot be or need
I have an application which has some classes that handle some specific functions, have
I have a some classes which I need to serialize in two different ways:
I have a package which contains an interface and several classes,some classes in this
I have some classes which extends a superclass, and in the JSP I want
I have some classes(call it Class A) which I would like to unit test
I'm using .NET 3.5. We have some complex third-party classes which are automatically generated
I have four classes which share some arrangement of four properties. I have currently

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.