Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > best /proper way to

Reply
Thread Tools

best /proper way to

 
 
James_Gale
Guest
Posts: n/a
 
      11-27-2005
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 : http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
 
 
 
zero
Guest
Posts: n/a
 
      11-27-2005
"James_Gale" <(E-Mail Removed)> wrote in
news:(E-Mail Removed) oups.com:

> 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 : (E-Mail Removed)
>
>


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
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      11-27-2005
On 27 Nov 2005 00:57:41 -0800, "James_Gale"
<(E-Mail Removed)> 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.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      11-27-2005
On Sun, 27 Nov 2005 17:55:59 GMT, Roedy Green
<(E-Mail Removed) > 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.
 
Reply With Quote
 
James_Gale
Guest
Posts: n/a
 
      11-30-2005
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 : (E-Mail Removed)

 
Reply With Quote
 
zero
Guest
Posts: n/a
 
      11-30-2005
"James_Gale" <(E-Mail Removed)> wrote in
news:(E-Mail Removed) ups.com:

> 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 : (E-Mail Removed)
>



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
 
Reply With Quote
 
James_Gale
Guest
Posts: n/a
 
      12-01-2005
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 : (E-Mail Removed)

zero wrote:
> "James_Gale" <(E-Mail Removed)> wrote in
> news:(E-Mail Removed) ups.com:
>
> > 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 : (E-Mail Removed)
> >

>
>
> 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


 
Reply With Quote
 
James_Gale
Guest
Posts: n/a
 
      12-01-2005
thanks Roedy,

James.

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      12-01-2005
On 30 Nov 2005 23:19:00 -0800, "James_Gale"
<(E-Mail Removed)> 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.
 
Reply With Quote
 
zero
Guest
Posts: n/a
 
      12-01-2005
"James_Gale" <(E-Mail Removed)> wrote in
news:(E-Mail Removed) oups.com:

> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Best way to loop through ArrayList and remove elements on the way? Kevin Java 16 01-30-2008 08:54 PM
way way way OT: MCNGP Announcement Neil MCSE 174 04-17-2006 05:55 PM
Any way/Best way to simulate 3:2 mode on an S2 IS? Joe Digital Photography 0 03-09-2006 05:35 PM
AMD Opteron: 1-way, 2-way, ... Up to 8-way. John John Windows 64bit 12 12-27-2005 08:17 AM
What is the best way to make dual-way xml databinding? Stan ASP .Net 3 05-05-2005 02:07 PM



Advertisments