Hey guys. I am new to Java programming and I am having a lot of difficulty figuring out how to get the proper functionality out of my first, last, next, and previous buttons. First, I was wondering if my button setup is correct:
// helper method that creates panel for buttons
private JPanel createButtonPanel() // returns a Jpanel
{
ActionListener btnListen = new ButtonListener(); // create my listerner
// Create button objects
firstButton = new JButton("First"); // create button object
firstButton.setActionCommand("First"); // add actionCommand
firstButton.addActionListener(btnListen); // add Listener command
nextButton = new JButton("Next"); // create button object
nextButton.setActionCommand("Next"); // add actionCommand
nextButton.addActionListener(btnListen); // add Listener command
previousButton = new JButton("Previous"); // create button object
previousButton.setActionCommand("Previous"); // add actionCommand
previousButton.addActionListener(btnListen); // add Listener command
lastButton = new JButton("Last"); // create button object
lastButton.setActionCommand("Last"); // add actionCommand
lastButton.addActionListener(btnListen); // add Listener command
// Create panel object
JPanel panel = new JPanel(); // instantiate a new JPanel
panel.add(firstButton); // add firt button to panel
panel.add(nextButton); // add next button to panel
panel.add(previousButton); // add previous button to panel
panel.add(lastButton); // add last button to panel
return panel; // return the panel
}
If so, I am sure that there needs to be embedded if statments that perform the looping for the next and previous buttons. The first and last buttons just need to be assigned to the first and last object in my array, so that is not a problem.