1.11M Members

GUI application to show employee record one time.

 
0
 

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
        Q1Field.setText(e.getName());
        // set text field with title
        Q2Field.setText(e.getName());
        // set textfield with salary
        Q3Field.setText(String.valueOf(e.getSalary()));
    }




    public void actionPerformed(ActionEvent x)
   {
        if (x.getSource() == Next)
   {
            index++;

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

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.

 
0
 

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!

 
1
 

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.

 
0
 

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.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: