There is a View:
public class View { public volatile String s; public void viewer() { JFrame frame = new JFrame(); JTextField t = new JTextField(); frame.add(BorderLayout.NORTH, t); frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE); frame.setSize(200, 200); frame.setVisible(true); t.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { s = t.getText(); } }); } There is a controller:
public class Main { public static void main(String[] args) throws InterruptedException { View view = new View(); view.viewer(); //Thread.sleep(20000); //while (view.s == null); System.out.println("smth"); } } How to put a stream to sleep until an event occurred in View (until all the fields were filled out)?
I commented on my two options. The first one falls asleep only for a fixed time and, accordingly, is not connected in any way with the event. The second while works fine, but it looks somehow wrong.
What is a more competent way, without loading the system with an unnecessary loop?
actionPerformedadd some sort ofcallback? - JVicactionPerformedevent afters = t.getText();your function will be fulfilled - JVic