> > Hello,
> >
[quoted text clipped - 25 lines]
> HTH
> Sergio
In my GUI code, I have
button1.addActionListener(new Button1Listener());
and in my Button1Listener class,
I need to access the jTextArea1 which is declared protected in my GUI
code (both classes are in the same package).
The problem is that to compile Button1Listener, I need the class file
of my GUI code and vice-versa. I am stuck in a deadlock here. There
must be some proper way to go about developing java projects, whose
knowledge I surely am missing.
This is the first time I am working in a live project, that's why a bit
stuck.
regards,
vijay.
Sergio - 10 Mar 2005 01:28 GMT
>>>Hello,
>>>
[quoted text clipped - 64 lines]
> regards,
> vijay.
As I suggested before, inestead of creating a new Button1Listener for
every single button, you may do something like this pseudocode:
in your GUI class:
uniqueButtonListener = new YourSpecializedButtonListener();
uniqueButtonListener.setTheTextAreaToRead(jTextArea1);
button1.addActionListener(uniqueButtonListener);
button2.addActionListener(uniqueButtonListener);
.
.
button897678.addButtonListener(uniqueButtonListener);
etc..
and your button listener class will be something like:
class YourSpecializedButtonListener extends ActionListener {
protected JTextArea theTextAreaToUse;
public void setTheTextAreaToRead(JTextArea textArea) {
theTextAreaToUse = textArea;
}
public void actionPerformed (ActionEvent event) {
String command = event.getActionCommand();
if(command.equals("whatever")) {
doWhateverYouHaveToDoWithTheJTextArea(theTextAreaToUse);
.
.
Now compile YourSpecializedButtonListener class and then the GUI class.
Best,
Sergio