Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

JAVA


  • Please log in to reply

#1
o0MattE0o

o0MattE0o

    Member

  • Member
  • PipPip
  • 29 posts
I'm not shore if there are meany java coders on this site :tazz: but can some one tell me a simple way to do this: -

class Member
private Vector member;

int memberNumber;
String firstname;
String surname;
String telephone;
String street;
String city;
Vector books;

class PnlMember extends JPanel
JTextField txtStaffNo = new JTextField();
JTextField txtFirstname = new JTextField();
JTextField txtSurname = new JTextField();
JTextField txtTelephone = new JTextField();
JTextField txtStreet = new JTextField();
JTextField txtCity = new JTextField();
JTextField txtHireDate = new JTextField();

and I want to add the info from the PnlMember into the private Vector member and later on add a Vector book later on...
  • 0

Advertisements


#2
o0MattE0o

o0MattE0o

    Member

  • Topic Starter
  • Member
  • PipPip
  • 29 posts
looks like no one knows java :tazz:

I attached a File if any one can ;) me Im haveing problems adding members to my vector

Attached Files


  • 0

#3
stu_design

stu_design

    Member

  • Member
  • PipPipPip
  • 217 posts
i know java somewhat
took high school course last year

never got involved wit vectors

but

http://www.leepoint..../40vectors.html

http://java.sun.com/...til/Vector.html

Stu Design

Hope that helps
  • 0

#4
o0MattE0o

o0MattE0o

    Member

  • Topic Starter
  • Member
  • PipPip
  • 29 posts
not really thats just a simple Vector I can creat Vectors
  • 0

#5
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts
are you required to use Vector? if not, why not use ArrayList?

FYI - Vector is one of the few flawed classes in java.
  • 0

#6
o0MattE0o

o0MattE0o

    Member

  • Topic Starter
  • Member
  • PipPip
  • 29 posts
its ok I have worked it out and yes Vector are flawed but it is dynamic and you dont have to set the size unlike an arrary where the size has to be set...

still gotto work out how to place anouther Vector inside a Vector
for example

I have made a Member Class (Vector) and in that there is a Book Class (Vector)

I have to update the member and add a book(s) for them?
any idears...

P.S just a fort but you have a OS in the profile why not have anouther part that has what filds they know I.E. XHTML XML JAVA FLASH PHOTOSHOP DATABASE ect.

Edited by o0MattE0o, 03 June 2005 - 03:00 PM.

  • 0

#7
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts

I have to update the member and add a book(s) for them


Member m = new Member();
m.member = new Vector();
Vector books = new Vector();
...
// add vector books to vector m.member
m.member.addElement( books );

a Vector holds objects, even other Vectors

when you have a chance, check out ArrayList() . it is different than Array(). it looks like it is too late for this project(based on the zip file), but I'm sure you'll find ArrayList() a pleasure to use.
  • 0

#8
o0MattE0o

o0MattE0o

    Member

  • Topic Starter
  • Member
  • PipPip
  • 29 posts
so would I have to have a variable in the Member:-

Vector books;
Or
Book books

and how do you get a current member say from a pull down box

Edited by o0MattE0o, 03 June 2005 - 04:14 PM.

  • 0

#9
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts

so would I have to have a variable in the Member:-

it is not necessary to add a variable to Member.

Vector books = new Vector();

books above is only a Vector(not Member, Books, ...)

if you wish, however, you could add Vector books to Member(as in post #1)

and how do you get a current member say from a pull down box

// put all Members into a Vector
// populate the pull down using the Vector holding current Members
// add code to return the Member selected from the pull down
  • 0

#10
o0MattE0o

o0MattE0o

    Member

  • Topic Starter
  • Member
  • PipPip
  • 29 posts
can some one please look at what I have and tell me what I have to edit to add the book to a member?


when you creat a member it displys it in a list to the right and also in the next tab and when you click a user and then select a book you can then click loan button that will add that book to that member and shown in the first tab if you click the same user.

this what I'm trying to do and I hope that makes sens :tazz:

Attached Files


  • 0

Advertisements


#11
o0MattE0o

o0MattE0o

    Member

  • Topic Starter
  • Member
  • PipPip
  • 29 posts
I have 2 panales

top one is a list of Members
bottom one is a list of Books (with a button on it that prints the selected book)

how would I link them together so instead of printing it will transfer the book to the member?

Posted Image

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

  • 0

#12
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts
here's an ArrayList() example - note it is not necessary to set the size
new code in red

import java.util.*;

public class Member{
...
private ArrayList bookList = new ArrayList();
...
public void testArrayList() {
Member m = new Member();
Book b = new Book();
m.addBook(b);
}

public void addBook(Book newBook){
bookList.add(newBook);
}

}

how would I link them together so instead of printing it will transfer the book to the member?

there is no need to 'link' anything together if you have a Member object and a Book object.
  • 0

#13
o0MattE0o

o0MattE0o

    Member

  • Topic Starter
  • Member
  • PipPip
  • 29 posts
Got some of it done

Library Panal
 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 btnPrintBook_actionPerformed(ActionEvent e) {
    Vector aBook = new Vector();
    aBook = pnlLibraryBooks.getBook();
    System.out.println(aBook);
}

:tazz:

Edited by o0MattE0o, 05 June 2005 - 12:11 PM.

  • 0

#14
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts
this looks like it would work.

this will return a Vector from the call to getBook()

Vector v = b.getBook(); // where b is the Book object
  • 0

#15
o0MattE0o

o0MattE0o

    Member

  • Topic Starter
  • Member
  • PipPip
  • 29 posts
all i need to do know is copy that for the member and then have a method like
 public void addBook(Vector addBook){
    this.member = addBook;
  }
in the member class
or have I got that wrong


and thank you for all your help :tazz: so far

Edited by o0MattE0o, 05 June 2005 - 12:26 PM.

  • 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