Skip to content

Commit

Permalink
Merge pull request #125 from Vavinan/97-close-insights-window-before-…
Browse files Browse the repository at this point in the history
…exit

Resolve: Close insights window before exit from the program
  • Loading branch information
Vavinan committed Apr 8, 2024
2 parents 9d2994b + c371f00 commit 078fbed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/budgetbuddy/BudgetBuddy.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import budgetbuddy.exceptions.InvalidEditTransactionData;
import budgetbuddy.exceptions.InvalidIndexException;
import budgetbuddy.exceptions.InvalidTransactionTypeException;
import budgetbuddy.insights.Insight;
import budgetbuddy.parser.Parser;
import budgetbuddy.storage.DataStorage;
import budgetbuddy.transaction.TransactionList;
Expand Down Expand Up @@ -42,12 +43,13 @@ public void run() {


boolean isRunning = true;

while (isRunning) {
String input = in.nextLine();
try {
switch (input.split(" ")[0]) {
case "bye":
Insight.closeInsightFrames();
UserInterface.printGoodBye();
isRunning = false;
break;
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/budgetbuddy/insights/Insight.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.util.ArrayList;
import java.awt.Window;

import static java.lang.Math.abs;

Expand Down Expand Up @@ -102,4 +103,18 @@ private static int indexOf(Category[] array, Category target) {
return -1;
}

//@@author Vavinan
public static void closeInsightFrames() {
// Close any open insight frames here
for (Window window : Window.getWindows()) {
if (window instanceof JFrame) {
String title = ((JFrame) window).getTitle();
if (title != null && (title.equals("Income Insights") || title.equals("Expense Insights"))) {
window.dispose();
}
}
}
}
//@@author

}

0 comments on commit 078fbed

Please sign in to comment.