I have an application which has 2 classes(form and execution) and 2 buttons. With first button I will execute entire function I want to be executed and I want the second button to execute a part of function. More exactly, after I press the second button it will finish a part of function and after that it will enter a while true and wait to be pressed again the second button. The problem there it's... all my program is stopped when I've press the second button.
Form class:
new Thread() {
@Override
public void run() {
debugChecker = 1;
exection(microCode);
debugChecker = 2;
}
}.start();
Execution class:
public static void exection(List<List<String>> microCode) {
for (int i = 0; i < microCode.size(); i++) {
OUTER:
for (int j = 0; j < microCode.get(i).size(); j++) {
STEP:
{
aluValue.setText(microCode.get(i).get(2));
String curentFunction = microCode.get(i).get(j);
switch (curentFunction) {
case "IF":
try {
check = true;
Method m = Registers.class.getMethod(microCode.get(i).get(j + 1));
boolean condition = (boolean) m.invoke(new Registers());
if (condition) {
if (!microCode.get(i).get(j + 2).equals("STEP")) {
String adr2 = microCode.get(i).get(j + 3);
String jump_adr = JUMPI(adr2);
microCode = UCODE.get(jump_adr);
if (jump_adr.matches("INT|CALL|NOT_RD|RET|RETI|IM_D|IM_S")) {
memoryOffset = offset;
} else {
memoryOffset = 0;
}
exection(microCode);
return;
} else if (microCode.get(i).get(j + 2).equals("STEP")) {
i++;
j = -1;
break STEP;
}
}
if (microCode.get(i).get(j + 2).equals("STEP")) {
j = j + 2;
} else {
j = j + 3;
}
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
Logger.getLogger(ExecutionMicroInstruction.class.getName()).log(Level.SEVERE, null, ex);
}
break;
case "ELSE":
if (microCode.get(i).get(j + 1).equals("STEP")) {
j += 1;
break OUTER;
} else if (JMP(microCode.get(i).get(j + 2)).equals("IFCH")) {
return;
} else {
String adr3 = microCode.get(i).get(j + 2);
String jump_adr3 = JUMPI(adr3);
microCode = UCODE.get(jump_adr3);
getCurentOperation(jump_adr3);
exection(microCode);
return;
}
case "STEP":
check = true;
break;
case "JUMPI":
check = true;
String instr2 = microCode.get(i).get(j + 1);
String address = JUMPI(instr2);
microCode = UCODE.get(address);
getCurentOperation(address);
if (address.matches("INT|CALL|NOT_RD|RET|RETI|IM_D|IM_S")) {
memoryOffset = offset;
} else {
memoryOffset = 0;
}
exection(microCode);
return;
case "JMP":
check = true;
if (JMP(microCode.get(i).get(j + 1)).equals("IFCH")) {
return;
}
microCode = UCODE.get(JMP(microCode.get(i).get(j + 1)));
getCurentOperation(JMP(microCode.get(i).get(j + 1)));
System.out.println("---" + JMP(microCode.get(i).get(j + 1)) + "---");
exection(microCode);
return;
default:
switch (debugChecker) {
case 0: {
String instruction = microCode.get(i).get(j);
List<String> list = microCode.get(i);
try {
if (check) {
mergeImagesByName(list);
check = false;
}
Method instr = Registers.class.getMethod(instruction);
instr.invoke(new Registers());
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
Logger.getLogger(ExecutionMicroInstruction.class.getName()).log(Level.SEVERE, null, ex);
}
break;
}
case 1: {
String instruction = microCode.get(i).get(j);
try {
mergeJustOneElemOnTime(instruction);
Method instr = Registers.class.getMethod(instruction);
instr.invoke(new Registers());
debugChecker = 2;
System.out.println(instruction);
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
Logger.getLogger(ExecutionMicroInstruction.class.getName()).log(Level.SEVERE, null, ex);
}
break;
}
case 2: {
while (debugChecker == 2) {
}
}
default:
break;
}
break;
}
}
}
}
}
EDITED:
I've tried with thread, but that's not what I want. Because if I will do with threads it will executed entire function. What I need is... when I will press on secondButton
I want to make JUST first step of this for, I want to do just j=j+1
after I've press again it will do this j=j+1
again, and so on. After it will finish with J it will take I, and so on. All what I want it's just one increment on time. Just it. And threads don't help me.