This discussion is archived
7 Replies Latest reply: Apr 3, 2008 10:43 AM by 807601 RSS

Adding array item when button clicked

807601 Newbie
Currently Being Moderated
When a button is clicked I want to take text from 4 different text fields and add them to the end of their respective arrays. I declared the array's as class arrays in a different JFrame, is it possible to take the text from this new JFrame's Textfields and add it to the arrays. Here's the code
  NewJFrame.AirlineName.add(jTextField1.getText());
NewJFrame is the original frame, then it pops up a new frame when a button is clicked. They add text to the textfields and click add. It will then take the text and add it to the arrays.
  • 1. Re: Adding array item when button clicked
    807601 Newbie
    Currently Being Moderated
    How high a standard should your code aspire to? It seems that you are making several basic mistakes: using class fields and mixing business logic into your presentation layer. You shouldn't do either.
  • 2. Re: Adding array item when button clicked
    807601 Newbie
    Currently Being Moderated
    well thank you for that, but you still didnt answer my question, if you dont know what the answer is then please dont post on my forums


    This is the error I am getting on compiling the program.
    symbol  : method add(java.lang.String)
    location: class java.lang.String[]
            NewJFrame.AirlineName.add(jTextField1.getText());
    Once again when you click the button it opens a new frame. Ask for input and writes the textfield input onto the end of the array. But it won't let you add the information. Both frames are in the same package. If you need more information just ask.
  • 3. Re: Adding array item when button clicked
    807601 Newbie
    Currently Being Moderated
    rhino17 wrote:
    well thank you for that, but you still didnt answer my question, if you dont know what the answer is then please dont post on my forums
    Saying this to BDLH. Now that's got to be one of funniest posts of the day!

    But seriously, he has an important point to make, that you may or may not choose to listen to. If you don't choose to listen to it, it will bite you in the end.
  • 4. Re: Adding array item when button clicked
    807601 Newbie
    Currently Being Moderated
    no problem, but can anybody answer my question?
  • 5. Re: Adding array item when button clicked
    807601 Newbie
    Currently Being Moderated
    1) when you say the words "pop up" and all, my guess is that you don't want a new JFrame but rather a dialog container such as a JDialog or a JOptionPane.
    2) Is this new "frame" or dialog or what have you modal? Does the user add information, click a button, and this window then disappears while your main program extracts the data?
    3) Much of what you're asking is how to have one object communicate with another. It is done no differently in GUIs as with non-GUI code. Both can use getters and setters, both can use an observer pattern when looser coupling is desired.
  • 6. Re: Adding array item when button clicked
    807601 Newbie
    Currently Being Moderated
    That might be the problem. I'm creating a whole new Jframe, not a dialog box. I'm new to this whole Java Business ( HS student, learning w/o an actual teacher) . I'll do reasearch on a dialog box, or if u have a quick link to a tut that would be great. And i did not understand BDLH's original message, he sounded like he was trying to be a ... you get the point.

    Is there a way to retrieve more than one input value?

    Edited by: rhino17 on Apr 3, 2008 10:27 AM

    Edited by: rhino17 on Apr 3, 2008 10:31 AM
  • 7. Re: Adding array item when button clicked
    807601 Newbie
    Currently Being Moderated
    rhino17 wrote:
    That might be the problem. I'm creating a whole new Jframe, not a dialog box.
    Using a dialog will probably make the GUI work more smoothly and will allow you to display and retrieve information modally, but won't change basic object to object communication.
    I'm new to this whole Java Business ( HS student, learning w/o an actual teacher) . I'll do reasearch on a dialog box, or if u have a quick link to a tut that would be great.
    [How to Make Dialogs|http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html]
    And i did not understand BDLH's original message, he sounded like he was trying to be a ... you get the point.
    If you stay around this board for long, you'll see that BDLH is one of the nicer posters around. He'll kid at times but almost always in a gentle fashion. I however can be a flaming asshole at times.
    Is there a way to retrieve more than one input value?
    Absolutely. For instance if you used a JOptionPane, you could place a JPanel within it that has several JTextFields, and easily extract this information. But note that there are always messy quick and dirty ways of doing this that don't scale well as your project grows or changes. What BDLH was suggesting was to keep your logic and your GUI separate and your class coupling loose so as to avoid these pitfalls. Also know this. If you see him disagreeing with something someone here says (including or especially me), I'd go with his interpretation over mine any day as he's a pro.