Simple demo, hope to help you understand
First, you need a listener to listen.
Listener. Java
package bbbb;public interface Listener {public void onComplete();}
Then a request is required to request the answer.
Requset. Java
Package BBBB; public class request {public request () {New answer (). thinking (new listener () {@ overridepublic void oncomplete () {// todo auto-generated method stubsystem. out. println ("thinking successful... ");}});}}
Finally, an answer is needed to answer the question.
Answer. Java
package bbbb;import java.awt.List;public class Answer {public void Thinking(final Listener l){new Thread(new Runnable() {@Overridepublic void run() {// TODO Auto-generated method stubtry {Thread.sleep(2000);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}l.onComplete();}}).start();}}
Main. Java
package bbbb;public class Main {public static void main(String arg[]){new Request();}}
In a simple demo, the general principle is to ask an answer for a request. After answer finishes thinking, the answer is placed in the listener .. Then the request will know the answer ..
Welcome to the discussion.