M
mehafi
Hi,
I wrote a class counter_button, which extends JButton class. The Text
of counter button is a value how much it was presed ( with additional
text):
public class counter_button
{
private int counter = 0;
public JButton button;
public counter_button()
{
button = new JButton("I was presed " + counter + " times");
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
button.setText("I was presed " + ++counter + " times");
});
}
}
and I use this class ( in anoter class ):
....
counter_button my_button = new counter_button();
JFrame f = new JFrame("my frame");
Container con = f.getContentPane();
con.add(my_button.prz);
It works fine! But, is it possible to write counter_button class to
use it like that:
con.add(my_button);
instead of:
con.add(my_button.prz);
thanks in advance
I wrote a class counter_button, which extends JButton class. The Text
of counter button is a value how much it was presed ( with additional
text):
public class counter_button
{
private int counter = 0;
public JButton button;
public counter_button()
{
button = new JButton("I was presed " + counter + " times");
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
button.setText("I was presed " + ++counter + " times");
});
}
}
and I use this class ( in anoter class ):
....
counter_button my_button = new counter_button();
JFrame f = new JFrame("my frame");
Container con = f.getContentPane();
con.add(my_button.prz);
It works fine! But, is it possible to write counter_button class to
use it like that:
con.add(my_button);
instead of:
con.add(my_button.prz);
thanks in advance