Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

JAVA


  • Please log in to reply

#16
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 875 posts
here's one possible way:

since all of the Members are included in the JTable rows, adding getMember() to PnlLibraryBooks will give you access to each Member object


void btnPrintBook_actionPerformed(ActionEvent e) {
Member m = new Member();
m = pnlLibraryBooks.getMember();
m.currentBook = pnlLibraryBooks.getBook();
}



// new method for PnlLibraryBooks
public Member getMember() {
// return Member based on selected row
}
  • 0

Advertisements


#17
o0MattE0o

o0MattE0o

    Member

  • Topic Starter
  • Member
  • PipPip
  • 29 posts
PnlSelectMember
 public Vector getMember() {
    int row = MemberTable.getSelectedRow();
    Vector selectedMember = new Vector();
    TableColumnModel colModel = MemberTable.getColumnModel();
    String isbn = (String) MemberTable.getValueAt(row, 0);
    String publisher = (String) MemberTable.getValueAt(row, 1);
    String author = (String) MemberTable.getValueAt(row, 2);
    String title = (String) MemberTable.getValueAt(row, 3);
    selectedMember.add(isbn);
    selectedMember.add(publisher);
    selectedMember.add(author);
    selectedMember.add(title);
    return selectedMember;
  }

PnlLibraryBooks
 public Vector getBook() {
    int row = bookTable.getSelectedRow();
    Vector selectedBook = new Vector();
    TableColumnModel colModel = bookTable.getColumnModel();

    String isbn = (String)bookTable.getValueAt(row, 0);
    String publisher = (String)bookTable.getValueAt(row, 1);
    String author = (String)bookTable.getValueAt(row, 2);
    String title = (String)bookTable.getValueAt(row, 3);

    selectedBook.add(isbn);
    selectedBook.add(publisher);
    selectedBook.add(author);
    selectedBook.add(title);

    return selectedBook;
  }

Main
 void btnPrintMember_actionPerformed(ActionEvent e) {
    Vector aBook = new Vector();
    aBook = pnlLibraryBooks.getBook();
    pnlSelectMember.getMember().add(aBook);
  }

The only problem is know is I cant get it to display it in the PnlMembersBooks changeing for each member

Edited by o0MattE0o, 06 June 2005 - 01:18 PM.

  • 0

#18
o0MattE0o

o0MattE0o

    Member

  • Topic Starter
  • Member
  • PipPip
  • 29 posts
I still need some help I cant get the books to display back up in the members list :tazz: can some one please help...

Attached Files

  • Attached File  GUI.zip   12.35KB   125 downloads

  • 0

#19
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 875 posts
been out of town since Sun. will be able to look at this later this evening.

question - is this a refresh problem(new books not shown), or are there no books listed at any time?
  • 0

#20
o0MattE0o

o0MattE0o

    Member

  • Topic Starter
  • Member
  • PipPip
  • 29 posts
I just spent half a day making this fully java compatible and not using borlands codding as it had trouble running on systems without borland installed...

And I'm not shore if its adding the book onto the table or not adding the books to the member...

:Update:
I think the problem is to do with my
btnBorrow_actionPerformed

its not adding a book to the selected member.

Attached Files


Edited by o0MattE0o, 08 June 2005 - 04:45 PM.

  • 0

#21
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 875 posts
good job - it looks like it's no longer relying on borland.

if the Vector book of a Member contains all borrowed books, then Vector book needs to be updated when a book is borrowed. and the Member object being displayed needs to be updated and refreshed.
  • 0

#22
o0MattE0o

o0MattE0o

    Member

  • Topic Starter
  • Member
  • PipPip
  • 29 posts
I know what to do have from the start it the matter of coding it I'm still learning as I'm going along and im not shore how I would call the Vector Book for each member to add the book...

ok I can do it the simple way like in the MembersBooksTest.class
but I cant add a book to the member as i need to get the same member form the table as in the one in the vector?

but I have not been told how to do this or what to look at to find out how to do this...

can you help me out as I know what I have to do have from the start its just coding it :tazz:

Edited by o0MattE0o, 09 June 2005 - 05:43 AM.

  • 0

#23
o0MattE0o

o0MattE0o

    Member

  • Topic Starter
  • Member
  • PipPip
  • 29 posts
Some one told me this but I dont understand it

in the member class why do you have a variable to member again? is this a linked list implementation?

your problem is that, you are returning new instances of a member each time, that way you have several copies.

public Vector getMember() {
int row = SelectMemberTable.getSelectedRow();
Vector selectedMember = new Vector();
TableColumnModel colModel = SelectMemberTable.getColumnModel();
String aMemberNumber = (String) SelectMemberTable.getValueAt(row, 0);
String aFirstname = (String) SelectMemberTable.getValueAt(row, 1);
String aSurname = (String) SelectMemberTable.getValueAt(row, 2);
String aTelephone = (String) SelectMemberTable.getValueAt(row, 3);
String aStreet = (String) SelectMemberTable.getValueAt(row, 4);
String aCity = (String) SelectMemberTable.getValueAt(row, 5);
String aAmount = (String) SelectMemberTable.getValueAt(row, 6);
selectedMember.add(aMemberNumber);
selectedMember.add(aFirstname);
selectedMember.add(aSurname);
selectedMember.add(aTelephone);
selectedMember.add(aStreet);
selectedMember.add(aCity);
selectedMember.add(aAmount);
return selectedMember;
}

you get the row number, seeing as the table should be backed by some model (Vector) you should use the row number with the vector, and return a reference to the instance.

You have far more code than you need. Keep the adding of a book and a member. However, when displaying members, books, also display the Vector books inside the member class so that you can see your results. Have a vector of users. A vector of books. Inside each user class have a vector books_borrowed. Use the values of the table as your vector values rather than copying. Once you click a row, get the row number. Use row number to get member for vector of members. Similarly use books. Then, add the book to the vector of books in member. Remember, when you are grabbing members, you dont copy strings from table.


  • 0

#24
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 875 posts
the following returns a Vector. it should return a Member object.

public Vector getMember() {
Vector selectedMember = new Vector();
...
return selectedMember;
}

1. try creating a Member object, then return a Member object:



//public Vector getMember() {
public Member getMember() {

Vector selectedMember = new Vector();
...
Member m = new Member( aMemberNumber, aFirstname , ... );
...
// return selectedMember;
return m;
}

2. modify btnBorrow_actionPerformed():

void btnBorrow_actionPerformed(ActionEvent e) {
Vector aBook = new Vector();
aBook = pnlLibraryBooks.getBook();
pnlSelectMember.getMember().add(aBook);
// Vector aMember = new Vector();
// aMember = pnlSelectMember.getMember();
// System.out.println(aMember);
}

3. extract the Member fields and update the GUI( setText() )
  • 0

#25
o0MattE0o

o0MattE0o

    Member

  • Topic Starter
  • Member
  • PipPip
  • 29 posts
I changed all that ignoring any thing with // on the line
apart from "pnlSelectMember.getMember().add(aBook);"
that is "pnlSelectMember.getMember().setBook(aBook);"

but I still get even after trying to add a book

console
Member Number: AAA, First Name: AAA, Surname: AAA, Telephone Number: AAA|| Address Street:AAA, City: AAA|| Join Date: AAA
Books: []
console

using this code
currentMembers = membership.getMember().getMember();
for (int i = 0; i < currentMembers.size(); i++) {
Member aMember = (Member) currentMembers.get(i);
System.out.println(aMember);
}


setBook code
public void setBook(Vector newBook){
this.book = newBook;
}
  • 0

Advertisements


#26
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 875 posts
this line is not adding Vector aBook to a Member object:
pnlSelectMember.getMember().add(aBook);

try adding the following to Member:
public void addBook( Vector newBook ) {
book.add( newBook );
}

modify the following:
void btnBorrow_actionPerformed(ActionEvent e) {
Vector aBook = new Vector();
aBook = pnlLibraryBooks.getBook();
// pnlSelectMember.getMember().add(aBook);
aMember = pnlSelectMember.getMember();
aMember.addBook(aBook);

System.out.println(aMember);
}

note: aMember needs to be a Member object, not a Vector. make sense?
  • 0

#27
o0MattE0o

o0MattE0o

    Member

  • Topic Starter
  • Member
  • PipPip
  • 29 posts
ok thank you.

I still have some problems tho as it will only add one book to that selected member? or is that just to do with the Print Method not looking at all books?

public String toString() {
return "Member Number: " + memberNumber+", First Name: "+firstname+", Surname: "+surname+", Telephone Number: "+telephone+"|| Address Street:"+street+", City: "+city+"|| Join Date: "+joinDate + "\n Books: " + book;
}

Edited by o0MattE0o, 09 June 2005 - 02:01 PM.

  • 0

#28
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 875 posts
Member m = new Member();
// m.book is a Vector - book.add(aBook) adds a Vector to m.book

here's a debug method for Member

public int getSize( ) {
return book.size();
}

void btnBorrow_actionPerformed(ActionEvent e) {
...
System.out.println(" size = " + m.getSize());
}

the size of m.book should increase every time a book is borrowed. if it doesn't, then m.book is the problem. if it does, then the display is a problem(need to display each object in m.book). I'll be out for a few hours - see if you can get it to work. good luck.
  • 0

#29
o0MattE0o

o0MattE0o

    Member

  • Topic Starter
  • Member
  • PipPip
  • 29 posts
ok thanx
I try and work it out but it is the Member Book thats the problem as its saying size = 1 no matter how meany times I click the button

thanx for your help and time but I have to hand this in Friday afternoon so I have to finish this uncompleated and hope for the best :tazz:

Edited by o0MattE0o, 09 June 2005 - 05:48 PM.

  • 0

#30
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 875 posts
hint - the constructor for Member does not retrieve Vector book.

hint - if the borrowed books are displayed at SelectMemberTable, Vector book can be retrieved along with the other Member fields in PnlSelectMember getMember().
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP