Skip to content
This repository was archived by the owner on Apr 11, 2025. It is now read-only.

Commit 9e43ca1

Browse files
authored
feature/add-new-main-screen (#6)
2 parents ad851be + b633833 commit 9e43ca1

File tree

4 files changed

+50
-46
lines changed

4 files changed

+50
-46
lines changed

src/main/java/com/codewithjosh/ExpenseTracker2k19/ExpensesScreen.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,8 @@ private void btnCloseActionPerformed(ActionEvent evt)
732732

733733
case JOptionPane.YES_OPTION:
734734
dispose();
735-
final MainScreen mainScreen = new MainScreen();
736-
mainScreen.setVisible(true);
735+
pref.putInt("user_id", 0);
736+
new MainScreen().setVisible(true);
737737
break;
738738

739739
case JOptionPane.NO_OPTION:
@@ -789,9 +789,7 @@ private void btnBackActionPerformed(ActionEvent evt)
789789
{
790790

791791
dispose();
792-
793-
final HomeScreen homeScreen = new HomeScreen();
794-
homeScreen.setVisible(true);
792+
new HomeScreen().setVisible(true);
795793

796794
}
797795

src/main/java/com/codewithjosh/ExpenseTracker2k19/HomeScreen.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -341,26 +341,21 @@ private void btnCloseMouseExited(MouseEvent evt)
341341
private void btnCloseActionPerformed(ActionEvent evt)
342342
{
343343

344-
final int response = JOptionPane.showConfirmDialog(this, "Are you sure you want to logout?", "Log Out", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
344+
final int response = JOptionPane.showConfirmDialog(this, "Are you sure you want to logout?", "Confirm Log Out", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
345345

346346
switch (response)
347347
{
348348

349349
case JOptionPane.YES_OPTION:
350+
pref.putInt("user_id", 0);
350351
dispose();
351-
final MainScreen mainScreen = new MainScreen();
352-
mainScreen.setVisible(true);
352+
new MainScreen().setVisible(true);
353353
break;
354354

355355
case JOptionPane.NO_OPTION:
356356
System.exit(0);
357357
break;
358358

359-
case JOptionPane.CANCEL_OPTION:
360-
break;
361-
362-
case JOptionPane.CLOSED_OPTION:
363-
break;
364359
}
365360

366361
}
@@ -516,18 +511,15 @@ private void navActionPerformed(ActionEvent evt)
516511
{
517512

518513
case 1:
519-
final IncomeScreen incomeScreen = new IncomeScreen();
520-
incomeScreen.setVisible(true);
514+
new IncomeScreen().setVisible(true);
521515
break;
522516

523517
case 2:
524-
final BudgetScreen budgetScreen = new BudgetScreen();
525-
budgetScreen.setVisible(true);
518+
new BudgetScreen().setVisible(true);
526519
break;
527520

528521
case 3:
529-
final ExpensesScreen expensesScreen = new ExpensesScreen();
530-
expensesScreen.setVisible(true);
522+
new ExpensesScreen().setVisible(true);
531523
break;
532524

533525
}

src/main/java/com/codewithjosh/ExpenseTracker2k19/MainScreen.java

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,16 @@ private void btnCloseMouseExited(MouseEvent evt)
394394
private void btnCloseActionPerformed(ActionEvent evt)
395395
{
396396

397-
System.exit(0);
397+
final int response = JOptionPane.showConfirmDialog(this, "Are you sure you want to exit?", "Confirm Exit", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
398+
399+
switch (response)
400+
{
401+
402+
case JOptionPane.YES_OPTION:
403+
System.exit(0);
404+
break;
405+
406+
}
398407

399408
}
400409

@@ -500,8 +509,7 @@ private void navRegisterActionPerformed(ActionEvent evt)
500509
{
501510

502511
dispose();
503-
final RegisterScreen registerScreen = new RegisterScreen();
504-
registerScreen.setVisible(true);
512+
new RegisterScreen().setVisible(true);
505513

506514
}
507515

@@ -619,7 +627,7 @@ private void btnLoginActionPerformed(ActionEvent evt)
619627
|| password.equals("******"))
620628
{
621629

622-
JOptionPane.showMessageDialog(null, "All fields are required!");
630+
JOptionPane.showMessageDialog(this, "All fields are required!", "Log In", JOptionPane.WARNING_MESSAGE);
623631

624632
if (username.equals("enter your username"))
625633
switch (current)
@@ -657,7 +665,7 @@ private void btnLoginActionPerformed(ActionEvent evt)
657665
else if (password.length() < 6)
658666
{
659667

660-
JOptionPane.showMessageDialog(null, "Password Must be at least 6 characters!");
668+
JOptionPane.showMessageDialog(this, "Password must be at least 6 characters!", "Log In", JOptionPane.WARNING_MESSAGE);
661669
pfPassword.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, new Color(255, 51, 51)));
662670
pfPassword.setForeground(new Color(255, 51, 51));
663671

@@ -712,7 +720,12 @@ public static void main(String args[])
712720
->
713721
{
714722

715-
new MainScreen().setVisible(true);
723+
final Preferences pref = Preferences.userNodeForPackage(Class.class);
724+
final int user_id = pref.getInt("user_id", 0);
725+
if (user_id != 0)
726+
new HomeScreen().setVisible(true);
727+
else
728+
new MainScreen().setVisible(true);
716729

717730
});
718731

@@ -899,28 +912,25 @@ private void onLogin(final String username, final String password)
899912
{
900913

901914
case 0:
902-
JOptionPane.showMessageDialog(null, "User Doesn't Exist!");
915+
JOptionPane.showMessageDialog(this, "User Doesn't Exist!", "Log In", JOptionPane.WARNING_MESSAGE);
903916
tfUsername.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, new Color(255, 51, 51)));
904917
tfUsername.setForeground(new Color(255, 51, 51));
905918
break;
906919

907920
case 1:
908-
JOptionPane.showMessageDialog(null, "Incorrect Password!");
921+
JOptionPane.showMessageDialog(this, "Incorrect Password!", "Log In", JOptionPane.WARNING_MESSAGE);
909922
break;
910923

911924
}
912925

913926
pfPassword.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, new Color(255, 51, 51)));
914927
pfPassword.setForeground(new Color(255, 51, 51));
915-
916928
break;
917929

918930
case 1:
919931
conn.close();
920932
dispose();
921-
final HomeScreen homeScreen = new HomeScreen();
922-
homeScreen.setVisible(true);
923-
933+
new HomeScreen().setVisible(true);
924934
break;
925935

926936
}
@@ -933,8 +943,7 @@ private void onLogin(final String username, final String password)
933943
| SQLException ex)
934944
{
935945

936-
JOptionPane.showMessageDialog(null, "Please Contact Your Service Provider");
937-
conn = SQLite.getInstance();
946+
JOptionPane.showMessageDialog(this, "An error occured while logging in", "Expense Tracker", JOptionPane.ERROR_MESSAGE);
938947

939948
}
940949

src/main/java/com/codewithjosh/ExpenseTracker2k19/RegisterScreen.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,16 @@ private void btnCloseMouseExited(MouseEvent evt)
417417
private void btnCloseActionPerformed(ActionEvent evt)
418418
{
419419

420-
System.exit(0);
420+
final int response = JOptionPane.showConfirmDialog(this, "Are you sure you want to exit?", "Confirm Exit", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
421+
422+
switch (response)
423+
{
424+
425+
case JOptionPane.YES_OPTION:
426+
System.exit(0);
427+
break;
428+
429+
}
421430

422431
}
423432

@@ -522,8 +531,7 @@ private void navLoginActionPerformed(ActionEvent evt)
522531
{
523532

524533
dispose();
525-
final MainScreen MainScreen = new MainScreen();
526-
MainScreen.setVisible(true);
534+
new MainScreen().setVisible(true);
527535

528536
}
529537

@@ -704,7 +712,7 @@ private void btnRegisterActionPerformed(ActionEvent evt)
704712
|| repassword.equals("******"))
705713
{
706714

707-
JOptionPane.showMessageDialog(null, "All fields are required!");
715+
JOptionPane.showMessageDialog(this, "All fields are required!", "Sign Up", JOptionPane.WARNING_MESSAGE);
708716

709717
if (username.equals("enter your username"))
710718
switch (current)
@@ -756,15 +764,15 @@ private void btnRegisterActionPerformed(ActionEvent evt)
756764
else if (password.length() < 6)
757765
{
758766

759-
JOptionPane.showMessageDialog(null, "Password Must be at least 6 characters!");
767+
JOptionPane.showMessageDialog(this, "Password must be at least 6 characters!", "Sign Up", JOptionPane.WARNING_MESSAGE);
760768
pfPassword.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, new Color(255, 51, 51)));
761769
pfPassword.setForeground(new Color(255, 51, 51));
762770

763771
}
764772
else if (!password.equals(repassword))
765773
{
766774

767-
JOptionPane.showMessageDialog(null, "Password doesn't match!");
775+
JOptionPane.showMessageDialog(this, "Password doesn't match!", "Sign Up", JOptionPane.WARNING_MESSAGE);
768776
pfPassword.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, new Color(255, 51, 51)));
769777
pfPassword.setForeground(new Color(255, 51, 51));
770778
pfRePassword.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, new Color(255, 51, 51)));
@@ -998,17 +1006,15 @@ private void onRegister(final String username, final String password)
9981006
ps.setString(2, password);
9991007

10001008
ps.execute();
1001-
JOptionPane.showMessageDialog(null, "You're Successfully Added!");
1009+
JOptionPane.showMessageDialog(this, "You're Successfully Added!", "Sign Up", JOptionPane.INFORMATION_MESSAGE);
10021010

10031011
conn.close();
10041012
dispose();
1005-
final MainScreen MainScreen = new MainScreen();
1006-
MainScreen.setVisible(true);
1007-
1013+
new MainScreen().setVisible(true);
10081014
break;
10091015

10101016
case 1:
1011-
JOptionPane.showMessageDialog(null, "Username is Already Taken!");
1017+
JOptionPane.showMessageDialog(this, "Username is Already Taken!", "Sign Up", JOptionPane.WARNING_MESSAGE);
10121018
tfUsername.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, new Color(255, 51, 51)));
10131019
tfUsername.setForeground(new Color(255, 51, 51));
10141020
break;
@@ -1023,8 +1029,7 @@ private void onRegister(final String username, final String password)
10231029
| SQLException ex)
10241030
{
10251031

1026-
JOptionPane.showMessageDialog(null, "Please Contact Your Service Provider");
1027-
conn = SQLite.getInstance();
1032+
JOptionPane.showMessageDialog(this, "An error occured while signing up", "Expense Tracker", JOptionPane.ERROR_MESSAGE);
10281033

10291034
}
10301035

0 commit comments

Comments
 (0)