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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:28:29+00:00 2026-05-29T22:28:29+00:00

I would like to describe the expected inputs of a Java class aimed to

  • 0

I would like to describe the expected inputs of a Java class aimed to perform a certain task,
within the Java class itself. The aim is to be able to generate the user interface directly be loading this class.

For example, assuming the base interface is Task (implementing Runnable):

public class BuildRectangleTask implements Task {
    public void setLength(double val) { /* ... */ }
    public void setWidth(double val) { /* ... */ }
    public void run() { /* Build a rectangle */ }
}

I could use some reflection to get the parameter names from this, and then build the
relevant part of a user interface from this, for example:

<form>
    <label for="length">Length: </label>
         <input type="text"name="length" id="length" /><br />
    <label for="width">Width: </label>
         <input type="text"name="width" id="width" />
</form>

This would probably work fine for very simple examples, but accessor names can’t always translate
properly into natural language without sounding awkward (they may also need to be translated).
In addition, I would also like to be able to have additional information (e.g. which ones would be optional or have default values).

I’m thinking of using annotations to describe this:

@Description(text="This tasks builds a rectangle")
public class BuildRectangleTask implements Task {
    @Input(label="Length", optional=false)
    public void setLength(double val) { /* ... */ }

    @Input(label="Width", optional=true, default=10,
           help="This is the width of the rectangle")
    public void setWidth(double val) { /* ... */ }

    public void run() { /* Build a rectangle */ }
}

This would also be useful for extra information, for example multiple choices:

@Input(label="Colour", options={"Red", "Green", "Blue"})

I would also like to be able to generate other types of user interfaces, for example a command-line, get-opt style like this based on the information:

java TaskProcessor BuildRectangle --help

usage: BuildRectangle --height= [ --width=10 ] [ --color= ]
Options:
    --height=   ...
    --width=    This is the width of the rectangle (defaults to 10).
    --color=    Red, Blue, Green.

Is there any standard set of annotations or usual framework for achieving this (or perhaps a different approach altogether), preferably compatible with Java and Groovy?

I would like the class to be self-contained as much as possible (i.e. avoid configuration files).
(I’m not necessarily interested in defining what the output of such a task would be and how it
should be displayed.)

  • 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-05-29T22:28:30+00:00Added an answer on May 29, 2026 at 10:28 pm

    You could try http://today.java.net/pub/a/today/2008/06/24/automatic-user-interface-with-openxava.html which is the sort of thing you want to do but probably the wrong framework! Might be a bit overkill though.

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

Sidebar

Related Questions

I would like to stub the #class method of a mock object: describe Letter
I would like to describe some specifics of my program and get feedback on
Would like to be able to set colors of headings and such, different font
I would like to Download Email attachment using SSIS.If possible,Please describe the process.
I Would like to check if a set of N points describe a convex
I would like to describe tests in BDD style e.g. with FlatSpec but keep
I have a batch of keywords that describe my site and I would like
I would like to test that the following function performs as expected: function throwNextTick(error)
I would like to implement an distributed Point-Of-Sale system, somewhat like the one described
I would like to know which dependency described in my pom.xml brings a transitive

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.