views:

116

answers:

1

This is homework. Beginning Java class. Still wrapping my head around this stuff.

This questions Extends this one

So there is a button for First, Prev, Next, and Last

Each should modify

Item ID, Name, Rating, Price, Units, Value, Fee, ValueW/Fee, Total Inventory Value

The last one is a static total of all units)

I am not sure if I should make each button do multiple calls like this.

productName.setText( product.getProductName() ); itemNumber.setText( String.valueOf( product.getItemNumber() ) );

Or make each JTextArea listen for the button then change its field. Does that even work?

+1  A: 

Register an ActionListener for each button. In the body of that ActionListener's actionPerformed method, get the item to display and pass it to a method that will be responsible for setting the values to the text fields.

Something like:

JButton button = new JButton("Next");
button.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        DVDObject obj = getNextDVD();
        populateFields(obj);
    }
});

...

private DVDObject getNextDVD() {
    // gets the next object to display
    // you could call this method for each of the buttons, 
    // passing in an argument that determines which Object
    // to return (first, last, next, previous, whatever)
}

private void populateFields(DVDObject dvd) {
    // write out the values from the object passed in to the
    // fields
}

I'm guessing you've got some kind of collection of objects that contain all the information about DVDs, I've taken a stab in the dark and called it "DVDObject" here.

rjohnston
OK like this?= Button (Actionlistener( currentDisplay++setTextFields(currentDisplay==))setTextFields(int display)fields[0].setText(inv.get(currentDisplay).getItem());fields[1].setText(inv.get(currentDisplay).getName());etc..
lazfish
Yeah I think I can work with that. I like the approach thanks!
lazfish
You've got to be joking. I gave you the answer in your last poting. Why are you wasting everybodys time asking the question over again.
camickr
I had posted my follow up before your edit.
lazfish