best /proper way to

Discussion in 'Java' started by James_Gale, Nov 27, 2005.

  1. James_Gale

    James_Gale Guest

    Hi,

    I'm a newbie and was wondering if you could help.

    I'd like to know the best /proper way to do the following, I think I
    could hack it to do something like what I want it to do, but I'd rather
    know the best /proper way to do it.


    I have a two forms the first contains a selectable list of items, an
    add, edit, delete and close button, the second contains various
    textboxs to add/ edit fields and a ok and cancel button.

    if the first form's selectable list of items is populated by a data
    model.
    On selection of an item and the edit button is clicked.

    What would I do next ? to get the


    Do I add the second form to the edit button as a Listener.

    How would I get the information as to what was selected to the second
    form, does the second form use the same one as the first form, or does
    it have its own data model.


    Any help or even a link would be greatly appreciated

    many thanks

    James

    e-mail :
     
    James_Gale, Nov 27, 2005
    #1
    1. Advertising

  2. James_Gale

    zero Guest

    "James_Gale" <> wrote in
    news::

    > Hi,
    >
    > I'm a newbie and was wondering if you could help.
    >
    > I'd like to know the best /proper way to do the following, I think I
    > could hack it to do something like what I want it to do, but I'd rather
    > know the best /proper way to do it.
    >
    >
    > I have a two forms the first contains a selectable list of items, an
    > add, edit, delete and close button, the second contains various
    > textboxs to add/ edit fields and a ok and cancel button.
    >
    > if the first form's selectable list of items is populated by a data
    > model.
    > On selection of an item and the edit button is clicked.
    >
    > What would I do next ? to get the
    >
    >
    > Do I add the second form to the edit button as a Listener.
    >
    > How would I get the information as to what was selected to the second
    > form, does the second form use the same one as the first form, or does
    > it have its own data model.
    >
    >
    > Any help or even a link would be greatly appreciated
    >
    > many thanks
    >
    > James
    >
    > e-mail :
    >
    >


    Please proofread your post before sending it - sentences like "to get
    the" don't make much sense to me.

    Are you coming from a VS environment? There's no such thing as a "form"
    in Java - you probably mean a window or frame?

    If I understand your question correctly, the best thing you can do is
    have an ActionListener on the edit button that will create the second
    frame if it doesn't exist yet, and show it if it does exist, after
    filling it with the correct data.

    --
    Beware the False Authority Syndrome
     
    zero, Nov 27, 2005
    #2
    1. Advertising

  3. James_Gale

    Roedy Green Guest

    On 27 Nov 2005 00:57:41 -0800, "James_Gale"
    <> wrote, quoted or indirectly quoted
    someone who said :

    >I have a two forms the first contains a selectable list of items, an
    >add, edit, delete and close button, the second contains various
    >textboxs to add/ edit fields and a ok and cancel button.


    Is this an HTML form you are generating with a Servlet or an Applet,
    or an application? Do you use AWT or Swing?

    I presume an ordinary application.

    You want the second frame to pop up when a button is pressed?

    Than you write an ActionListener in the first frame for the button
    than does

    FrameType2 frame2 = new FrameType2( ..... );
    frame2.setVisible();
    and possibly
    frame2 = null; if frame2 is not local.

    You can pass frame2 some information, e.g. an interface to frame1 in
    the constructor.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Nov 27, 2005
    #3
  4. James_Gale

    Roedy Green Guest

    On Sun, 27 Nov 2005 17:55:59 GMT, Roedy Green
    <> wrote, quoted or
    indirectly quoted someone who said :

    >frame2.setVisible();

    or more precisely possibly a
    frame2.validate();
    or
    frame2.pack();
    then
    frame2.setVisible( true );
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Nov 27, 2005
    #4
  5. James_Gale

    James_Gale Guest

    Sorry for my misuse of English.

    I will try to explain myself better.

    I have created two classes (which I called forms)

    The first class "listView" is a jframe containing
    a couple of jPanels, a jscrollpanes containing a jtable. Four jbuttons
    "add", "edit", "delete" & "close".

    The second class "itemView" is again a jframe containing a jtable. Two
    jbuttons "Ok" & "Cancel"

    I have a datamodel for populating the jtable in the first class
    "listView".

    I also have a main class.

    The listView class is passed the datamodel on creation, the information
    is shown in the jtable which has row selection only set, and is
    non-editable.

    The user select a row and then clicks the action to be perform
    "add","edit" or "delete".
    On selecting an action the second class is shown, detailing the
    information to be edited.
    On completion of the any editing etc.. the user can select either "ok"
    to keep the changes or "cancel".

    How would it be best to proceed.

    Would it be better to create the itemView class and passing it the
    datamodel used by listView, from each buttons ActionListener.

    OR

    Could I have the itemView class as an ActionListener itself and
    listView would notify it when an action was selected. ie. add, edit,
    delete or which row in the list was selected.
    What way the itemView class is not "hardcoded" into the listView class.

    many thanks

    James

    e-mail :
     
    James_Gale, Nov 30, 2005
    #5
  6. James_Gale

    zero Guest

    "James_Gale" <> wrote in
    news::

    > Sorry for my misuse of English.
    >
    > I will try to explain myself better.
    >
    > I have created two classes (which I called forms)
    >
    > The first class "listView" is a jframe containing
    > a couple of jPanels, a jscrollpanes containing a jtable. Four jbuttons
    > "add", "edit", "delete" & "close".
    >
    > The second class "itemView" is again a jframe containing a jtable. Two
    > jbuttons "Ok" & "Cancel"
    >
    > I have a datamodel for populating the jtable in the first class
    > "listView".
    >
    > I also have a main class.
    >
    > The listView class is passed the datamodel on creation, the information
    > is shown in the jtable which has row selection only set, and is
    > non-editable.
    >
    > The user select a row and then clicks the action to be perform
    > "add","edit" or "delete".
    > On selecting an action the second class is shown, detailing the
    > information to be edited.
    > On completion of the any editing etc.. the user can select either "ok"
    > to keep the changes or "cancel".
    >
    > How would it be best to proceed.
    >
    > Would it be better to create the itemView class and passing it the
    > datamodel used by listView, from each buttons ActionListener.
    >
    > OR
    >
    > Could I have the itemView class as an ActionListener itself and
    > listView would notify it when an action was selected. ie. add, edit,
    > delete or which row in the list was selected.
    > What way the itemView class is not "hardcoded" into the listView class.
    >
    > many thanks
    >
    > James
    >
    > e-mail :
    >



    I would use neither. Instead, give each of the buttons an ActionListener
    of its own (you could use 4 anonymous classes for this, or one class that
    handles them all). In those listeners, populate and show the ItemView
    class. For example:

    public class ListView
    {
    private ItemView itemView;
    // ...

    public ListView(...)
    {
    // ...
    JButton addButton = new JButton("add");
    addButton.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    itemView.setData(getSelectedData());
    itemView.show();
    }
    });
    // ...
    }

    // ...
    }

    getSelectedData would give a list/array/vector/... of the selected row.
    ItemView:setData would use this data to fill out the text fields.

    If you don't like the close relationship between ItemView and ListView,
    you could implement a Controller which passes information between the
    two.

    --
    Beware the False Authority Syndrome
     
    zero, Nov 30, 2005
    #6
  7. James_Gale

    James_Gale Guest

    Many thanks zero,

    You mentioned a Controller, is this using Model-View-Controller, do you
    know of any examples of how to use this.

    James

    e-mail :

    zero wrote:
    > "James_Gale" <> wrote in
    > news::
    >
    > > Sorry for my misuse of English.
    > >
    > > I will try to explain myself better.
    > >
    > > I have created two classes (which I called forms)
    > >
    > > The first class "listView" is a jframe containing
    > > a couple of jPanels, a jscrollpanes containing a jtable. Four jbuttons
    > > "add", "edit", "delete" & "close".
    > >
    > > The second class "itemView" is again a jframe containing a jtable. Two
    > > jbuttons "Ok" & "Cancel"
    > >
    > > I have a datamodel for populating the jtable in the first class
    > > "listView".
    > >
    > > I also have a main class.
    > >
    > > The listView class is passed the datamodel on creation, the information
    > > is shown in the jtable which has row selection only set, and is
    > > non-editable.
    > >
    > > The user select a row and then clicks the action to be perform
    > > "add","edit" or "delete".
    > > On selecting an action the second class is shown, detailing the
    > > information to be edited.
    > > On completion of the any editing etc.. the user can select either "ok"
    > > to keep the changes or "cancel".
    > >
    > > How would it be best to proceed.
    > >
    > > Would it be better to create the itemView class and passing it the
    > > datamodel used by listView, from each buttons ActionListener.
    > >
    > > OR
    > >
    > > Could I have the itemView class as an ActionListener itself and
    > > listView would notify it when an action was selected. ie. add, edit,
    > > delete or which row in the list was selected.
    > > What way the itemView class is not "hardcoded" into the listView class.
    > >
    > > many thanks
    > >
    > > James
    > >
    > > e-mail :
    > >

    >
    >
    > I would use neither. Instead, give each of the buttons an ActionListener
    > of its own (you could use 4 anonymous classes for this, or one class that
    > handles them all). In those listeners, populate and show the ItemView
    > class. For example:
    >
    > public class ListView
    > {
    > private ItemView itemView;
    > // ...
    >
    > public ListView(...)
    > {
    > // ...
    > JButton addButton = new JButton("add");
    > addButton.addActionListener(new ActionListener()
    > {
    > public void actionPerformed(ActionEvent e)
    > {
    > itemView.setData(getSelectedData());
    > itemView.show();
    > }
    > });
    > // ...
    > }
    >
    > // ...
    > }
    >
    > getSelectedData would give a list/array/vector/... of the selected row.
    > ItemView:setData would use this data to fill out the text fields.
    >
    > If you don't like the close relationship between ItemView and ListView,
    > you could implement a Controller which passes information between the
    > two.
    >
    > --
    > Beware the False Authority Syndrome
     
    James_Gale, Dec 1, 2005
    #7
  8. James_Gale

    James_Gale Guest

    thanks Roedy,

    James.
     
    James_Gale, Dec 1, 2005
    #8
  9. James_Gale

    Roedy Green Guest

    On 30 Nov 2005 23:19:00 -0800, "James_Gale"
    <> wrote, quoted or indirectly quoted
    someone who said :

    >You mentioned a Controller, is this using Model-View-Controller, do you
    >know of any examples of how to use this.


    The controller is the most custom part. It is the application logic.
    It decides what changes based on various inputs. Typically it calls
    methods of the model, and the model is turn fires change events that
    cause parts of the View to be repainted.

    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Dec 1, 2005
    #9
  10. James_Gale

    zero Guest

    "James_Gale" <> wrote in
    news::

    > Many thanks zero,
    >
    > You mentioned a Controller, is this using Model-View-Controller, do
    > you know of any examples of how to use this.
    >
    > James
    >


    well in your case it's not really the model-view-controller pattern since
    it would be relaying messages between two "view" classes. It's based on
    the same pattern though. It more fits the OO idea of low coupling
    (uncoupling the link between ListView and ItemView, so that they can be
    changed independently).
    Whether or not to use a controller in your case is a pure design decision.

    --
    Beware the False Authority Syndrome
     
    zero, Dec 1, 2005
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve C. Orr, MCSD

    Re: What is a proper way to set up smtp

    Steve C. Orr, MCSD, Jul 2, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    372
    jaekim
    Jul 3, 2003
  2. Brandon Potter

    Proper Way to work with SQL Connections

    Brandon Potter, Jan 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    363
    Kevin Spencer
    Jan 23, 2004
  3. Diego Martins
    Replies:
    5
    Views:
    5,421
    Diego Martins
    Jun 19, 2007
  4. Hal Fulton
    Replies:
    1
    Views:
    185
    Gregory Brown
    Nov 5, 2009
  5. oldyork90
    Replies:
    1
    Views:
    179
    Jeremy J Starcher
    Sep 10, 2008
Loading...

Share This Page