Results 1 to 4 of 4
  1. #1
    venkatesh09 is offline Member
    Join Date
    Jul 2009
    Posts
    1
    Rep Power
    0

    Default get the details from GUI screen into an java object.

    Hi,
    I need to find solution for the below requiremet.

    I have created 2 classes, say class1.java,class2.java.
    Here class2.java uses GUI screen using swing.

    I need to get the details user entered in GUI screen through textbox into class1 after the user click enter button.

    So far i did like, I have created a object obj2 of class2 in class1 and call the GUI screen. But i couldnot able to get the details entered by user into class1.

    If anybody know, please tell how to get those details from GUI screen to
    class1?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    1) Have you considered having your GUI class hold an instance of the non-GUI class?
    or
    2) Connect the two with a Control class that contains ActionListeners and other listeners.

  3. #3
    Harpreet1111 is offline Member
    Join Date
    Jul 2009
    Posts
    12
    Rep Power
    0

    Default

    just make class2 implement ActionListener interface and attach an action listener with the button in class1 by using addActionListener(ActionListener a) method.

    Pass the object of class2 to the above method with textfiekds reference in the constructor.....

    than call the the getText() method of textfield in class2's actionPerformed() method......to get the result

  4. #4
    josemoncas's Avatar
    josemoncas is offline Member
    Join Date
    Jul 2009
    Location
    Madrid (Spain)
    Posts
    11
    Rep Power
    0

    Default

    There are different approches:

    1. You can have a reference to the class containing the user data in the other class.
    2. You can have an ActionListener (or other listeners) to listen to the user. The listener would be instantiated in the class1 and you can add it to class2 by having, for example, a getListenerForClass2() in you class1.
    3. You can use the Observer pattern.
    4. You can use Property firing.
    ...

    For me, the easiest way would be the first one.

    Hope it helps.
    The web that offers Java utilities (classes) which make programming Swing applications an easier task: JMC Java utilities

Similar Threads

  1. Replies: 2
    Last Post: 11-26-2010, 02:12 AM
  2. clear screen prompt using java code
    By krunalpatel1410 in forum Advanced Java
    Replies: 9
    Last Post: 04-04-2009, 12:47 AM
  3. java program for updating bank details
    By java__beginner in forum New To Java
    Replies: 5
    Last Post: 03-12-2009, 03:42 PM
  4. Blank Screen while navigating from one screen to another
    By mohana.krishna in forum Java Servlet
    Replies: 0
    Last Post: 03-03-2009, 05:03 PM
  5. Clear screen in java
    By lenny in forum New To Java
    Replies: 1
    Last Post: 07-30-2007, 09:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •