0

Good evening!

I'm working on an assignment, and I'm not seeing what is wrong with my logic here. Any assistance would be greatly appreciated.

It's a basic appointment book, and if there is an appointment at the current time, I would like the "New Appointment" button disabled. However, if I press the "Next" button, it disables the button whether there is an appointment there or not.

Here is the actionPerformed:

if (e.getSource()==this.nextButton){          //If "Next" is pressed
            appointments.next();                      //go to next appt time
            timeField.setText(appointments.getTime());//display the new time
            nameField.setText(appointments.getName());//display the appointment
            if (appointments.getName() == null){
                newButton.setEnabled(true);
            }else {
                newButton.setEnabled(false);
            }
}

And the function from the class I'm trying to call:

public String getName(){            //function gets the text for appointment
        return text[position];          //pulling the text that corresponds with
    }

Thank you in advance for pointing out my (likely silly and blatanly obvious) mistake.

- Jim

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by javaAddict
0
if (appointments.getName() == null){
                newButton.setEnabled(true);
            }else {
                newButton.setEnabled(false);
            }

According the above, the button is disabled when the the getName is not null. If it always get disabled it means it is always not null. Therefor your logic must have sort of mistake when you call appointments.next(); or
you might want to check if the String is empty

if ( (appointments.getName() == null) || (appointments.getName().equals("")) ) {
                newButton.setEnabled(true);
            }else {
                newButton.setEnabled(false);
            }

Of course we don't know your logic and you should focus on getting the correct value after the next.
Add some "system.out.println" to see what values you return

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.