How to make a thread to wait for another class to be terminated and continue the code?

1

As described in the precise code of a solution to give a pause in main until it waits for some call to continue the code of the main class. I know this is resolved with thread , but so far I have not figured out how to use it for this. I also think there has to be EDT , but I do not know much about thread , so I can not do it.

import javax.swing.JFrame;

public class Main extends JFrame{

    public Main(){
        setSize(800,600);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }



    public static void main(String[] args) {
        Main frame = new Main();
        Painel painel = new Painel();
        painel.setVisible(true);

        frame.add(painel);

        // Aguardar comando do Painel e continuar o código seguinte:

        System.out.println("OK");
        frame.remove(painel);

    }

}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;

public class Painel extends JPanel implements ActionListener {

    JButton button = new JButton("Prosseguir main");

    public Painel(){
        button.setVisible(true);
        add(button);
        button.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==button) {
            System.out.println("Escrever agora o OK no console e remover painel pela Main");
        }

    }
}
    
asked by anonymous 16.12.2017 / 09:28

0 answers