D:\841052795.doc 2/3
}
private void propertyChange(String name, int oldValue,int newValue) {
Iterator ite = listeners.iterator();
PropertyChangeListener l;
PropertyChangeEvent evt = new PropertyChangeEvent(this, name,
new Integer(oldValue), new Integer(newValue));
while (ite.hasNext()) {
l = (PropertyChangeListener)ite.next();
l.propertyChange(evt);
}
}
}
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class CaseReglable extends JPanel {
private class ReglageListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (e.getSource()== btPlus) {
value++;
if (value > max) value = min;
} else {
value--;
if (value < min) value = max;
}
tfCase.setText(String.valueOf(value));
}
} // fin class ReglageListener
// proriétés
private BorderLayout layout = new BorderLayout();
private JTextField tfCase = new JTextField();
private JPanel pReglage = new JPanel();
private GridLayout reglageLayout = new GridLayout();
private ImageIcon iiPlus = new ImageIcon("plus.gif");
private ImageIcon iiMoins = new ImageIcon("minus.gif");
private JButton btPlus = new JButton(iiPlus);
private JButton btMoins = new JButton(iiMoins);
private ReglageListener reglageListener = new ReglageListener();
private int value = 0;
private int max;
private int min;
private ArrayList listeners = new ArrayList();
// constructeur
public CaseReglable(int min, int max) {
this.min = min;
this.max = max;
setLayout(layout);
add(tfCase,BorderLayout.CENTER);
pReglage.setLayout(reglageLayout);
pReglage.add(btPlus);
pReglage.add(btMoins);
tfCase.setColumns((String.valueOf(max)).length()+1);
btPlus.setPreferredSize(new
Dimension(iiPlus.getIconWidth(),btPlus.getHeight()));
btMoins.setPreferredSize(new
Dimension(iiMoins.getIconWidth(),btMoins.getHeight()));
add(pReglage,BorderLayout.EAST);
setValue(0);
btPlus.addActionListener(reglageListener);
btMoins.addActionListener(reglageListener);