Click to See Complete Forum and Search --> : JAVA button problems


Geat
09-22-2003, 10:29 AM
We're currently developing an applet for editing web pages, and we've come across a problem.

The user has previously chosen a colour scheme and as such has an arbitrary number of colours they can select for text. We create the interface for the pallette with buttons, which are created via a loop. However, the event listener does not accept the button as a valid object from which to display the value.

Basically, how do we create an unfixed number of buttons with listeners thereon?

Khalid Ali
09-22-2003, 01:19 PM
If I understand it correctly,what you can do is create a generic class that has psecific(custome) methods for your possible events and then when you create any button you can do something like this

JButton xButton = new JButton();
xButton.addActionListener(new CustomEventClass());

something along these lines