Re: TextField
"man4*.*" <no@no.com> wrote in message news:eifvkb$j3s$1@news1.carnet.hr...
THX, I've modified you're code a litle bit and found what I was looking
for..
So, I'm new in swing (new also in Java :-) ) and I was wondering....
I'm creating one let's call it aplication, with few buttons, TexFields,
RadioButt., comboBox...
right now, I'm creating classes for each component like:
class T1A implements ActionListener {
public void actionPerformed(ActionEvent e) {
tf1.setText(tf2.getText() );
}
}
and calling it with tt2.addActionListener(new T1A());
and now I have to code at least 10 new classes, is there any other way?
at the moment I'm learning, and I'm coding each line, not using any GUI
builder...and that's a
lot of code to write.. ;-)
You don't even need any new classes.
Just have the class that you are writing (the one that contains
all the buttons, texts, etc.) implement ActionListener.
Then for each button:
button.addActionListener(this);
and create an actionPerformed() method in your class
that checks the source:
public void actionPerformed(ActionEvent e) {
Object obj = e.getSource();
if ( obj == button ) {
// do something
}
else if ( obj == button2 ) {
// etc.
}
}
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project