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

  • Home
  • SEARCH
  • 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 868981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:14:01+00:00 2026-05-15T10:14:01+00:00

Is there a lib that can build a simple GUI by looking at a

  • 0

Is there a lib that can build a simple GUI by looking at a class or method signature?

For Example:

class MyMath{
    public static double sqrt(double d){
         //impl
    }
}       

To

gui

So that when the button is clicked the method is invoked and the result is shown.

Do you know any examples of something like that in Java or other languages?

thanks

  • 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-15T10:14:01+00:00Added an answer on May 15, 2026 at 10:14 am

    I coded a very basic example, which shows how this can be achieved using a few lines reflection code and little swing. Maybe init() should return the number of methods found for use in the GridLayout, then it would be more dynamic.

    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.lang.reflect.Method;
    import java.util.HashMap;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    
    public class MathPanel extends JFrame {
    
        public static double sqrt(double d) {
            return Math.sqrt(d);
        }
    
        public static double sin(double d) {
            return Math.sin(d);
        }
    
        public static double cos(double d) {
            return Math.cos(d);
        }
    
        class Item implements ActionListener {
            JTextField result = new JTextField();
            JTextField param = new JTextField();
            JButton button;
            Method m;
            public Item(JFrame frame,String name, Method m) {
                button = new JButton(name);
                button.addActionListener(this);
                this.m = m;
                frame.getContentPane().add(param);
                frame.getContentPane().add(button);
                frame.getContentPane().add(result);
            }
    
            public void actionPerformed(ActionEvent e) {
                String cmd  = e.getActionCommand();
                Item item = map.get(cmd);
                try {
                    double dbl = Double.parseDouble(item.param.getText());
                    Object invoke = item.m.invoke(this, dbl);
                    item.result.setText("" + invoke );
                } 
                catch (Exception x) {
                    x.printStackTrace();
                }
            }
        }
    
        HashMap<String,Item>map = new HashMap<String, Item>(); 
    
    
        public MathPanel() {
            setLayout(new GridLayout(3,3));
            setTitle("Test");
            setSize(400, 100);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);
        }
    
        private void init() {
            try {
                Method[] allMethods = MathPanel.class.getDeclaredMethods();
                for (Method m : allMethods) {
                    String mname = m.getName();
                    Class<?> returnType = m.getReturnType();
                    if ( returnType.getName().equals("double")) {
                        Item item = new Item(this,mname,m);
                        map.put(mname,item);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        public static void main(String[] args) {
            MathPanel mp = new MathPanel();
            mp.init();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem (simplified to make things clearer): 1. there is one statically-linked static.lib that has
I have a binary file - Windows static library (*.lib). Is there a simple
In lib\RT\CustomFieldValues\ there is the groups.pm file which is supposed to be an example
There is a conversion process that is needed when migrating Visual Studio 2005 web
There are a few ways to get class-like behavior in javascript, the most common
There are two weird operators in C#: the true operator the false operator If
There are two popular closure styles in javascript. The first I call anonymous constructor
There is previous little on the google on this subject other than people asking
There seem to be many ways to define singletons in Python. Is there a
There are numerous Agile software development methods. Which ones have you used in practice

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.