buttons and arrays

I am "very" new to java, so don't laugh at my programming (o.k., you laugh)....and for class I have written a basic program which creates a basic GUI. The GUI should have four buttons (first, next, previous, and last). They should work, but I can't seem to write the code correctly to iterate through the array. Can anyone help? Here is the part of the code that is handling this event:

private class ButtonHandler implements ActionListener

{

public void actionPerformed(ActionEvent event)

{

int current = 0;// define a current value

int maximum = 0;// start with the first value

for (int i = 0; i < Accounting.MAXIMUM_ITEMS; i++)

{

if (i < maximum)

{

maximum = i;// new maximum

current = i;

currnext = current++;

last = product.getName();

next = product[currnext].getName();

}

}

if (event.getActionCommand().equals("Last"))

{

System.out.println();

System.out.println("You have selected: " + last);

}

if (event.getActionCommand().equals("Next"))

{

System.out.println();

System.out.println("You have selected: " + next);

}

}

}

Thank you!

[1249 byte] By [aspire_to_programa] at [2007-11-26 14:16:34]
# 1

Please try posting again with code tags.

I will say that this looks suspicious to me

int current = 0; // define a current value

int maximum = 0; // start with the first value

for (int i = 0; i < Accounting.MAXIMUM_ITEMS; i++)

{

if (i < maximum)

cotton.ma at 2007-7-8 2:06:42 > top of Java-index,Java Essentials,New To Java...
# 2
Ok, this is a dumb question. What are code tags? You mean the color coded comments?Thank you.
aspire_to_programa at 2007-7-8 2:06:42 > top of Java-index,Java Essentials,New To Java...
# 3

The [code] and [/code] tags as described in [url=http://forum.java.sun.com/help.jspa?sec=formatting ]Formatting tips[/url] on the message entry page.

Example

When you put this

[code]

private String myString = "Hello World!";

[/code]

It turns out like this

private String myString = "Hello World!";

cotton.ma at 2007-7-8 2:06:42 > top of Java-index,Java Essentials,New To Java...
# 4

Ok. I hope I do this right. Here goes nothing....

private class ButtonHandler implements ActionListener

{

public void actionPerformed(ActionEvent event)

{

int current = 0;// define a current value

int maximum = 0;// start with the first value

for (int i = 0; i < Accounting.MAXIMUM_ITEMS; i++)

{

if (i < maximum)

{

maximum = i;// new maximum

current = i;

currnext = current++;

last = product[i].getName();

next = product[currnext].getName();

}

}

if (event.getActionCommand().equals("Last"))

{

System.out.println();

System.out.println("You have selected: " + last);

}

if (event.getActionCommand().equals("Next"))

{

System.out.println();

System.out.println("You have selected: " + next);

}

}

}

aspire_to_programa at 2007-7-8 2:06:42 > top of Java-index,Java Essentials,New To Java...
# 5
i is never less than maximum. That's going to be a problem.
cotton.ma at 2007-7-8 2:06:42 > top of Java-index,Java Essentials,New To Java...
# 6

Ok. So I changed to >. However, it still doesn't do what I want it to do. Right now if you click on Last, you do get the last element in the array, however, if you click on Next, you also get the last element in the array. I would presume that it would either fail since there are no more elements or that it would start over at the top. Am I wrong in this assumption?

aspire_to_programa at 2007-7-8 2:06:42 > top of Java-index,Java Essentials,New To Java...
# 7
I would put some System.out.println(...). statements in the critical parts of your program to print out what the values are to see if the code is doing what you think it's doing.
hungyee98a at 2007-7-8 2:06:42 > top of Java-index,Java Essentials,New To Java...
# 8
ok. thank you.
aspire_to_programa at 2007-7-8 2:06:42 > top of Java-index,Java Essentials,New To Java...