We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,737 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

GUI application to show employee record one time.

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;
    }
3
Contributors
4
Replies
4 Hours
Discussion Span
1 Year Ago
Last Updated
5
Views
angeriel1
Newbie Poster
7 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

NormR1
Posting Sage
Team Colleague
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16

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!

angeriel1
Newbie Poster
7 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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.

NormR1
Posting Sage
Team Colleague
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16

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.

hfx642
Posting Pro
515 posts since Nov 2009
Reputation Points: 248
Solved Threads: 105
Skill Endorsements: 1

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.1116 seconds using 2.68MB