49 lines
1.4 KiB
Java
49 lines
1.4 KiB
Java
package Controller;
|
|
|
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
|
import java.util.Scanner;
|
|
|
|
import Model.ModelData;
|
|
import Model.MyModel;
|
|
|
|
import View.MyView;
|
|
|
|
public class Main {
|
|
public static void main(String[] args) {
|
|
ConcurrentLinkedQueue<ModelData> qDataFromModel = new ConcurrentLinkedQueue<ModelData>();
|
|
|
|
Object oThreadLock = new Object();
|
|
|
|
MyModel oModel = new MyModel(oThreadLock, qDataFromModel);
|
|
|
|
ModelData oModelData = new ModelData("");
|
|
|
|
MyView oView = new MyView(oModelData);
|
|
|
|
int iCommand = 2;
|
|
|
|
oModel.start();
|
|
|
|
while (iCommand != 0) {
|
|
Scanner oScanner = new Scanner(System.in);
|
|
System.out.print("Enter command: ");
|
|
iCommand = oScanner.nextInt(); //TODO remove statement if gui finished
|
|
|
|
oModel.setModelCommand(iCommand);
|
|
//Wake up model thread if new task to execute.
|
|
synchronized(oThreadLock) {
|
|
oThreadLock.notifyAll();
|
|
}
|
|
|
|
while (qDataFromModel.isEmpty() && (iCommand == 1)) {
|
|
//Wait for model to finish TODO remove loop if gui is finished
|
|
}
|
|
if (!qDataFromModel.isEmpty()) {
|
|
oModelData = qDataFromModel.poll();
|
|
System.out.println("Data received from Model:\n" + oModelData.getModelString());
|
|
}
|
|
}
|
|
System.out.println("Main-Thread stopped.");
|
|
}
|
|
}
|