• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need Help With GUI

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Android Mac OS X Firefox Browser Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
reply
    Bookmark Topic Watch Topic
  • New Topic