I have this progrom which is compiling and running.Only Iam tryin to understand how to change the action listener Next en previous such that,If i have 5 employees in record it when you reach the last employee in record the Next and previous buttons should be disabled.please advise
here is the action listener part of the code.

public Employee1(EmployeeDataSet employees) 

        this.numberOfEmployees = employees.getEmployeeCount();
        this.employees = employees;

    public void loadEmployeeInGUI(Employee e)
        // set text field with name
        // set text field with title
        // set textfield with salary

    public void actionPerformed(ActionEvent x)
        if (x.getSource() == Next)

            if(index == this.numberOfEmployees) index=0;
            Employee e = employees.getEmployeeAtIndex(index);
        if (x.getSource() == Previous) index--;
        if (index ==-1) index = this.numberOfEmployees -1;

Recommended Answers

All 4 Replies

when you reach the last employee in record the Next and previous buttons should be disabled

Do you know how to detect when the last employee record has been reached?
Do you know how to disable a button? Read the API doc for the button class for a method to use.

You right its my first doing this.i was just reading most of the stuff en putting it together.I have been checking the API the results am geting are on the fetch forward and reverse topic which isnt really making sense. i ve tried but it messes my whole program.but thanx nway!

but it messes my whole program

If you get errors you need to post the full text of the error message if you want help with them.

To see how to enable and disable buttons, write a small simple GUI program with two buttons.
Have one enabled and one disabled. Add action listeners to both buttons.
When the button is pressed, have the action listener disable the button that was pressed and enable the other button.

If you have problems with this program, post it here with your questions.

Member Avatar for hfx642

Get the count of the total number of records.
Keep track of which record you are on.
If you're on the 1st record, disable previous.
If you're on the 2nd record, enable previous.
If you're on the last record, disable next.
If you're on the 2nd last record, enable next.
You'll run into difficulties when you only have 1 record,
but we have to leave some stuff for you to figure out on your own.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.