Exit Button improved:

Exit button behaviour was just setting flags.
    This caused the program to set the exit flag when
    it is paused and wont exit until the unpause. Some other
    Funky stuff when the sim ends are fixed.
This commit is contained in:
HeshamTB 2021-01-05 17:11:43 +03:00
parent 5be16de49f
commit 5e1ff6451c

View File

@ -32,6 +32,7 @@ public class MakkahCity {
private static final Thread t = new Thread(inputListener,"InputThread-Makkah"); private static final Thread t = new Thread(inputListener,"InputThread-Makkah");
private static boolean isAllRoutSet; private static boolean isAllRoutSet;
private static final DataManeger dataManeger = new DataManeger(); private static final DataManeger dataManeger = new DataManeger();
private static volatile boolean done_flag;
//GUI //GUI
private static boolean exit_flag; private static boolean exit_flag;
private static boolean pause_flag; private static boolean pause_flag;
@ -212,7 +213,10 @@ public class MakkahCity {
btnExit.setFont(new Font("Rockwell", Font.PLAIN, 16)); btnExit.setFont(new Font("Rockwell", Font.PLAIN, 16));
btnExit.setForeground(Color.white); btnExit.setForeground(Color.white);
btnExit.setBounds(888, 623, 166, 29); btnExit.setBounds(888, 623, 166, 29);
btnExit.addActionListener(actionEvent -> exit_flag = true); btnExit.addActionListener(actionEvent -> {
if (pause_flag || done_flag) System.exit(0);
else exit_flag = true;
});
btnPause = new JButton("Pause"); btnPause = new JButton("Pause");
btnPause.setBackground(new Color(9,9,9)); btnPause.setBackground(new Color(9,9,9));
@ -530,6 +534,7 @@ public class MakkahCity {
//lblArrivedToHotelsTime.setText(getDistTimeForLbl()); //lblArrivedToHotelsTime.setText(getDistTimeForLbl());
} }
//When done show menu to analyze. Exit from menu too. //When done show menu to analyze. Exit from menu too.
done_flag = true;
inputListener.pause(); inputListener.pause();
startMenu(); startMenu();
} }