Gurtej Grewal

Ranch Hand
+ Follow
since Apr 28, 2021
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Gurtej Grewal

I was getting pretty bored today and and decided I wanted to make some random small programs to test some small skills like coming up with "algorithms" /processes to do something. Ex: reversing string, fizzBuzz, etc. What are some other examples of these that i can do?
5 days ago
Im wondering if JavaFx has anything similar to layout managers in swing where i wouldnt need to set a specific location on the screen for each part. And if anyone has any suggestions on where i can learn more about the javaFX syntax that would be great!
6 days ago
Hey Welcome To the Ranch! Reading your post im a little confused on what you want this program to do...but what i understand is you want a program that will ask the user for how many people are being served and return the total number of each ingredient required. Couple Things to mention:

1. If you only plan to use scanner to read Integer values, using nextInt() is fine, however in my experience, mixing scanner next*() can cause several problems. If you do intend to use both, i suggest parsing nextLine() values into an integer when neccesary.

2. Why use the base quantity as 4? Why not tell the program that 1 person requires 'This Much' rice, 'This Much' shrimp, etc. Then depending on user input, multiply each quantity by the number of people.

3. I wouldnt suggest doing `int rice, shrimp, squid;` on Line 6, this is a small program and you dont need to save space by doing this, it would be much better if you perhaps set these variables as finals holding values of how much is needed for 1 person

Hope This Helps!

Edit: Why do you need the second method? Its 1 line of code directly related to the input your getting from your main method, might as well keep it all in the same method.
1 week ago
So i know its good practice to split different functions of a code into different classes to keep it organized, but what if these functions shared many variables? for Example i have a class for gui grpahic setup(making and placing buttons, labels, etc) and a separate class for verifying login/account creation details when a button is pressed. The constructor is getting filled with variables and as i have learned, OOP tends to see each class sharing limited variables. Should i be keeping these two classes together?
1 week ago
It does Fix the Null issue, however when it is moved to the end of BankPanel(), theres a new issue. When i try logging in, it doesnt let me(As it should), however when i add a new account, pressing 'Create Account' doesnt let me in, but when i type the same account back into login, it does. the problem here is that it now allows Anything entered into the text and password fields into the rest of the program instead of whats in the map. I also printed the array which holds the password and balance and the password field shows up empty.
1 week ago
Im getting this NullPointerException which seem to be pointing to whenever i check the variables newUser, newPass, checkUser, checkPass. I did some research on java docs and StackOverflow and saw that its because the values are not being initialized with a value, therefore are null. I decided to initialize it with = "";. This fixed my null Exception issue however it seems as though the values are not updating from .getText() and are seen as "Empty". Im not sure how to fix this now.

StackTrace For Creating An Account

StackTrace For Logging In

GUI Desgin Class

Functionality Class
1 week ago
The Map itself can only have 1 value assigned per key, so using the array (and in my case not an ArrayList because there are a set number of values) lets me have both the Balance and Password under the same Username Key
1 week ago
I cant keep both password(String) and balance(int) in the same array to hold the values, would it be effective to keep balance as a string value and edit the string value everytime balance is changed?
1 week ago

Carey Brown wrote:In BankFrame you add() a new BankPanel but then you change the layout manager of the frame

Ive removed the setLayoutManager() from the frame (it was unnecessary and leftover from the start if the project). Ive also decided(for now) to keep the program under one class(plan is to get it working as intended at least), it seems to have fixed most of the issues, except the checkAccounts() isnt able to find the username and password in the map.

1 week ago
main calls BankFrame and BankFrame adds BankPanel
1 week ago
Im trying to make a simple program that logins a user by either creating an account and adding the username and password to a map. the key of the map being the account balance. Im having a couple issues solving so ill break each down.

1. I want to keep a separate class for the visuals of the GUI and another for adding accounts, checking to see if accounts exist, updating account balances, etc. However when i pass the account username and password (newUser, newPass) to the class, it says the values are always null. (See Next issue for attempted fix)

2. I temporarily fixed the null error above by initializing the values(however im not sure if this is how it is meant to be fixed) when i try to run the program now i am given a stack overflow error, im not sure what is being recursive to cause this.

Main Method Class

Frame Class

Panel Class:
Functionality Class:
1 week ago
Im trying to make it so that when the user clicks a button, they are taken to a JTable used to display user transaction history, however whenever the program is run, it displays a NullPointerException error along with a list of JComponent errors and Repaint errors, what am i missing from this code?

Right now when the gui is run, everything works fun until when this code is used, at this point the previous panel stays on the screen looking frozen, but as i hover my mouse over the top, the column names of the table appear ontop of the old panel.

I initially had a line however it caused many errors including a classCastingException.
1 week ago
Im setting up a small Login/Signup pages, i have this button that is meant to return the user to the option screen where they can pick wether to login or signup, the button worked fine on 'page 2' however when i added the same button onto page 3, it stopped working on page 2 and worked on page 3. whats the reason for this? do i have to recreate the same button with the same function everytime i want to use it on a different page? View Line 18 and 13 for the back buttons

1 week ago
Update: The Login And Signup Buttons were being added to this. instead of the panelOption, Works Good Now
1 week ago
So here i have 3 pages.
Page1: Ask the user if they want to login or sign up
Page 2 and 3: Signup page and Login page

The program starts with the Login and Signup Option, however when either one is clicked, instead of switching pages, it displays the label beside the original page.

Note*I know the screen is larger than it needs to be, the background colour wasnt working when i frame.pack(), ill fix that when i can get the pages working

Quick side Question on Line 83 of Panel Class

Main Class

Frame Class

Panel Class

1 week ago