Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

best /proper way to

Thread view: 
James_Gale - 27 Nov 2005 08:57 GMT
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 : euphoriahardhouse@yahoo.co.uk
zero - 27 Nov 2005 13:01 GMT
> Hi,
>
[quoted text clipped - 27 lines]
>
> e-mail : euphoriahardhouse@yahoo.co.uk

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.

Signature

Beware the False Authority Syndrome

Roedy Green - 27 Nov 2005 17:55 GMT
On 27 Nov 2005 00:57:41 -0800, "James_Gale"
<euphoriahardhouse@yahoo.co.uk> 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.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Roedy Green - 27 Nov 2005 18:18 GMT
On Sun, 27 Nov 2005 17:55:59 GMT, Roedy Green
<my_email_is_posted_on_my_website@munged.invalid> wrote, quoted or
indirectly quoted someone who said :

>frame2.setVisible();
or more precisely possibly a
 frame2.validate();
 or
 frame2.pack();
then
 frame2.setVisible( true );
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

James_Gale - 01 Dec 2005 07:20 GMT
thanks Roedy,

James.
James_Gale - 30 Nov 2005 09:41 GMT
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 : euphoriahardhouse@yahoo.co.uk
zero - 30 Nov 2005 12:58 GMT
> Sorry for my misuse of English.
>
[quoted text clipped - 42 lines]
>
> e-mail : euphoriahardhouse@yahoo.co.uk

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.

Signature

Beware the False Authority Syndrome

James_Gale - 01 Dec 2005 07:19 GMT
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 : euphoriahardhouse@yahoo.co.uk

> > Sorry for my misuse of English.
> >
[quoted text clipped - 77 lines]
> you could implement a Controller which passes information between the
> two.
Roedy Green - 01 Dec 2005 08:31 GMT
On 30 Nov 2005 23:19:00 -0800, "James_Gale"
<euphoriahardhouse@yahoo.co.uk> 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.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

zero - 01 Dec 2005 14:06 GMT
> 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.

Signature

Beware the False Authority Syndrome



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.