1,105,402 Community Members

GUI application to show employee record one time.

Member Avatar
angeriel1
Newbie Poster
7 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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;
    }
Member Avatar
NormR1
Posting Sage
7,723 posts since Jun 2010
Reputation Points: 563 [?]
Q&As Helped to Solve: 793 [?]
Skill Endorsements: 16 [?]
Team Colleague
 
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.

Member Avatar
angeriel1
Newbie Poster
7 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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!

Member Avatar
NormR1
Posting Sage
7,723 posts since Jun 2010
Reputation Points: 563 [?]
Q&As Helped to Solve: 793 [?]
Skill Endorsements: 16 [?]
Team Colleague
 
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.

Member Avatar
hfx642
Posting Pro
515 posts since Nov 2009
Reputation Points: 164 [?]
Q&As Helped to Solve: 105 [?]
Skill Endorsements: 1 [?]
 
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 three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: