JAVA - Geeks to Go Forums

Jump to content

Log in Register Register Malware removal guide How it works

JAVA JTABLE

#1 o0MattE0o

  • Group: Member
  • Posts: 29
  • Joined: 31-May 05

Posted 02 June 2005 - 02:56 PM

I have a library system and I have got this piece of code that will display the books into a JTable and when you click on one book it will print it in the console but I need to find out how to link it to my members class and display the book they loan out for each member can some one please :tazz: me

private void display() {
    data = new Vector();
    books = library.getBook().getBook();
    for (int i =0; i<books.size(); i++) {
      Book libraryBooks = (Book) books.get(i);
      Vector row = new Vector();
      row.add(libraryBooks.getISBN());
      row.add(libraryBooks.getPublisher());
      row.add(libraryBooks.getAuthor());
      row.add(libraryBooks.getTitle());
      row.add(new Double(libraryBooks.getAmount()));
      data.add(row);
      System.out.println("Testing Library Book Storage"+"\n"+libraryBooks);
    }
    model = new DefaultTableModel(data, columns);
    bookTable.setModel(model);
  }

  void bookTable_mouseClicked(MouseEvent e) {
    //String isbn=null;
    //String publisher=null;
    //String author=null;
    //String title=null;
    //Double amount=null; //going to change to int

    int row = bookTable.getSelectedRow();
    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);
    Double amount = (Double)bookTable.getValueAt(row, 4); //going to change to int

    /* ////////////////////////////////////////////////
    for(int col=0;col<colModel.getColumnCount();col++){
      Object value = bookTable.getValueAt(row, col);
      if(col==0){
        isbn = (String)value;
      }
      else if(col==1){
        publisher = (String)value;
      }
      else if(col==2){
        author = (String)value;
      }
      else if(col==3){
        title = (String)value;
      }
      else if(col==4){ 
        amount = (Double)value; //going to change to int
      }

    }
    //////////////////////////////////////////////// */

    System.out.println("ISBN: " + isbn + ", Publisher: " + publisher + ", Author: " + author + ", Title: " + title + " , Amount: " + amount);
  }

}


I can send the whole program I have so far if it helps

#2 o0MattE0o

  • Group: Member
  • Posts: 29
  • Joined: 31-May 05

Posted 03 June 2005 - 04:25 AM

no one on here can help then ;)

please :tazz:

Share this topic: