Problem with and event handler?

Hey i am kinda new to java and i am writing a calendar program for my AP Computer Science class i have a buttons as my calendar dates and when they are clicked they bring up a text box to store appoints and such it was working fine and now i cant seem to find what is going on thankspublicvoid actionPerformed(ActionEvent e)

{

JButton j = (JButton) e.getSource();

if(hasAppt(j))

{

if(datesList.size() > 0)

JOptionPane.showMessageDialog(this, datesList.get(datesList.size() - 1).getAppointment(mnth, Integer.parseInt(j.getText()), yer).toString());

}

else

{

String s = (String)JOptionPane.showInputDialog("Enter your appointment",

"Appointment");

if(s ==null)

return;

else

{

datesList.add(new AppointmentHandler("Brian"));

datesList.get(datesList.size() - 1).addAppt(s, mnth, Integer.parseInt(j.getText()), yer);

}

try

{

datesList.get(datesList.size() - 1).writeObjToDisk();

}

catch(IOException excep)

{

System.out.println("Error in saving object to disk: " + excep);

}

catch(ClassNotFoundException excep)

{

System.out.println("Error in saving object to disk: " + excep);

}

}

}

and this is where it adds the buttons in another method

for(int i = 0; i < dayNum[cal.daysInMnth-1]; i++)

{

JButton dayButton =new JButton();

dayButton.setText(Integer.toString(dayNum[i]));

dayButton.setPreferredSize(new Dimension(105, 25));

dayButton.addActionListener(this);

dayButtons.add(dayButton);

pack();

}

[2810 byte] By [brianb7590a] at [2007-11-27 4:09:02]
# 1
What happens now - do the buttons appear and, if so, what happens when you click on them?
pbrockway2a at 2007-7-12 9:14:25 > top of Java-index,Java Essentials,New To Java...
# 2
well the buttons come up but when i click them they dont do anything at all and when i set breakpoints at the actionPerfromed method it never gets called.
brianb7590a at 2007-7-12 9:14:25 > top of Java-index,Java Essentials,New To Java...
# 3

> well the buttons come up but when i click them they dont do anything at all

> and when i set breakpoints at the actionPerfromed method it never gets called.

I assume you are setting the breakpoint right at the start of actionPerformed. That is double check and confirm that the event handler is not being called. A simpleSystem.out.println(e);

will also tell you.

Check in the code that creates the buttons that you are adding the right thing as the event listener. ("this")

It may be that you have to construct and post a small example that will compile and run, which show how those buttons are constructed and added (and removed if they are removed). It doesn't have to include all the disk i/o stuff.

pbrockway2a at 2007-7-12 9:14:25 > top of Java-index,Java Essentials,New To Java...
# 4
the thing is that it never goes to the actionPerformed method when the button is clicked it doesnt call that method and i do send "this" to the button. it was working fine before i put the if(hasAppt) in there
brianb7590a at 2007-7-12 9:14:25 > top of Java-index,Java Essentials,New To Java...
# 5

> it was working fine before i put the if(hasAppt) in there

That's my point. You put this code in the actionPerformed() method - so it can only make a difference if that method is called! As I said you can check with certainty if actionPerformed() is called (as distinct from being called but not behaving as you expect), by using System.out.println(). It's low tech, but it will do the job.

Note: if hasAppt(j) is true and datesList.size()==0, your event handler will be invoked but do nothing. You may not expect these two conditions to be true, but something unintended is going on.

pbrockway2a at 2007-7-12 9:14:25 > top of Java-index,Java Essentials,New To Java...
# 6
alright i got it it is being called but i just isnt doing anything like you said i think i can fix it from here thanks
brianb7590a at 2007-7-12 9:14:25 > top of Java-index,Java Essentials,New To Java...