D
D
d3coy_002019-12-22 20:53:09
Java
d3coy_00, 2019-12-22 20:53:09

Sticky interface button or how to add a Swing function call to an event?

There is a code:

//Обработчик при нажатии на кнопки в окошке интерфейса
    class ListenerAction_start implements ActionListener {
      public void actionPerformed(ActionEvent e) {
            System.out.println("\n" + "Вы выбрали -> ["+ 
                                e.getActionCommand() + "]" + "\n");
            Start_main();
        }
    }
    
    class ListenerAction_stop implements ActionListener {
      public void actionPerformed(ActionEvent e) {
            System.out.println("\n" + "Вы выбрали -> ["+ 
                                e.getActionCommand() + "]" + "\n");
        }
    }
    
    // подключение монитора событий нажатия на кнопки интерфейса
    button.addActionListener(new ListenerAction_start());
    button2.addActionListener(new ListenerAction_stop());


Why, after a single click on the first button, it sticks by calling the Start_main () function. How to make it so that when the button is pressed, the Start_main function is called, and when button2 is pressed, another function is called without blocking the interface window (without sticking)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Cheremisin, 2019-12-22
@leahch

Your main processing cycle is blocked. Use SwingYtilities. invokeLater() and wrap it in Runnable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question