Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need Help With GUI  RSS feed

 
Kelley Rafferty
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am a beginner with Java. I have a school project right now to code a GUI application. I'm stuck on a few things. First, I am asking for user input via a panel with messages and text fields, it is for class assignments, and asks for the assignment name, month due, and then day due. I have a next button for the user to utilize if they have more assignments to enter. For the life of me I cannot figure out how to loop it so that the user can enter multiple assignments. I also want to save the assignment information as an assignment object which then saves into an ArrayList, but I'm having problems with that as well. If anyone can help me out and give me some pointers, I would greatly appreciate it as I am so frustrated at this point. Thanks!!
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the ranch.

What have you done so far? Do you have a Assignment class? The GUI (displaying the panel/text fields)?
 
Kelley Rafferty
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I have the assignment class. I also have the GUI. I have it so that the user can enter the data needed. I have a "Next" button if there is another assignment to enter, but that is where I get stuck. How do I get the input to save and then another blank window pop up? Do I just need to write that into the event listener for that button? If so, I'm unsure how I regenerate the window again. I have a new one pop up, but the old one is staying open, too.
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well the next button should have an "action listener" to tell it what it does (refresh the panel, save the data, do something else).

Check out the Swing tutorial event listeners here to get you started.

As for the components, I think there are 2 possible ways to refresh page: 1) set blank to all components (text box etc) or 2) repaint the pane or frame.

Either approach has its pros and cons. The first approach tends to be easier I think but more lines of code depending on number of components.
 
Kelley Rafferty
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, thank you. I will give that a shot. Makes a lot of sense. Thanks for your time!
 
Kelley Rafferty
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, I am still stuck on how to get my output. I have my Assignment Class and my Assignment Manager class, but I'm still lost for some reason. Maybe just frustration?? Can anyone help?? I'm so new, I don't even know how to post my code right.... So far I have for my "done button":

Just do not know where to go at this point....
 
Campbell Ritchie
Marshal
Posts: 55747
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have added code tags to your post; always use them: doesn't it look better

I think you are on the right lines, but that method is too long.
Let's start simply. What happens when you write this sort of thing?
 
Kelley Rafferty
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it does look much better. Thank you! I will read up more on the code tags, I wasn't quite sure how to do it and I was in a rush last night. Thank you for your help! I will get back to your post after work.
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy. I see you got some code going for the "done" button. Looks good so far.

First you should remember that your "action listener" class (DoneButtonListener) should have access to the JTextFields variables assignNameTF, monthDueTF, dayNumberDueTF, which I assume is outside your action listener (which is fine). If the DoneButtonListener class does NOT have access to those text fields ... make them instance variables rather than local variables.



Just curious what is the "validate()" and "repaint()" methods? If repaint, you mean refresh the screen then those textfield.setText("") lines are not needed. Put those in the repaint method. As for validate, what needs validating?

Also just a side note, if your form is a month/day calendar kind of input, you may want to use a JComboBox for the month and day instead, so that people wouldn't input wrong values. And your listener is guaranteed to get the correct values (given it is selected eg not null).
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!