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

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

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.