0

Following is the code to input proxy settings from user.

 public static void setProxy()
     {   
      java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new proxy().setVisible(true);
        }
    });
// Control should halt here till user gives input as it assigns value to the variables
    String host = prox;
    String port = prt;
    System.out.println("Using proxy: " + host + ":" + port);

2 Answers 2

2

You're not doing it correctly. The main method of a GUI application should do only one thing: start the GUI. The rest of the logic will be triggered by events fired by the user interacting with the GUI.

So, assuming your GUI displays a frame containing 2 text fields to enter the host and the port and a button to proceed, you should have, in your GUI, an action listener on the button:

proceedButton.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        String host = hostTextField.getText();
        String port = portTextField.getText();
        doSomethingWithHostAndPort(host, port);
    }
});

If doSomethingWithHostAndPort() does domething long, then it should do it in a separate thread, to avoid freezing the GUI.

Sign up to request clarification or add additional context in comments.

Comments

0

You need to provide more information if you want a precise answer. But I'm going to make a few assumptions, you have a button which is pressed after information is entered, that button has an on click event attached to it, that is where you add your variable assignments and start the processing.

1 Comment

..did you also forget to finish that comment? Mention what?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.