D:\841052795.doc 1/3
package pannHoraire;
import java.awt.*;
import javax.swing.*;
import pannHoraire.panneauHoraire;
public class fenPanHor
{
public static void main(String[] args) {
// // test panneau horaire
panneauHoraire pnaHur = new panneauHoraire();
JFrame fenHeur = new JFrame();
fenHeur.getContentPane().add(pnaHur,BorderLayout.CENTER);
fenHeur.setSize(200,60);
fenHeur.setVisible(true);
}
}
import java.beans.*;
import java.util.*;
import javax.swing.*;
public class panneauHoraire extends JPanel {
private int heure;
private int minute;
// get et set
public int getHeure() {
return crHeure.getValue();
}
public int getMinute() {
return crMinute.getValue();
}
public void setHeure(int i) {
int oldHeure = getHeure();
crHeure.setValue(i);
propertyChange("heure",oldHeure,i);
}
public void setMinute(int i) {
int oldMin = getMinute();
crMinute.setValue(i);
propertyChange("minute",oldMin,i);
}
private class ClicListener implements ClicCase {
public void clic(ClicEvent cv) {
if (cv.getSource()== crHeure) {
}
}
}
private BoxLayout layout = new BoxLayout(this, BoxLayout.X_AXIS);
private CaseReglable crHeure = new CaseReglable(0,23);
private CaseReglable crMinute = new CaseReglable(0,59);
private ArrayList listeners = new ArrayList();
private ClicListener clicListener = new ClicListener();
public panneauHoraire() {
add(crHeure);
add(crMinute);
crHeure.addClicListener(clicListener);
crMinute.addClicListener(clicListener);
}
public void addPropertyChangeListener (PropertyChangeListener l) {
listeners.add(l);
}
public void removePropertyChangeListener (PropertyChangeListener l) {
listeners.remove(l);
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);
D:\841052795.doc 3/3
}
// get set de value
public int getValue() {
return value;
}
public void setValue(int i) {
value = i;
tfCase.setText(String.valueOf(value));
}
public String getText() {
return String.valueOf(getValue());
}
public void addClicListener(ClicCase cc) {
listeners.add(cc);
}
public void removeClicListener(ClicCase cc) {
listeners.remove(cc);
}
private void clic(int oldValue) {
Iterator ite = listeners.iterator();
ClicCase cc;
ClicEvent ce = new ClicEvent(this,oldValue,getValue());
while (ite.hasNext()) {
cc = (ClicCase)ite.next();
cc.clic(ce);
}
}
}
public class ClicEvent {
private int oldValue;
private int newValue;
private Object source;
public ClicEvent(Object s,int ov,int nv) {
source = s;
oldValue = ov;
newValue = nv;
}
// get
public int getNewValue() {
return newValue;
}
public int getOldValue() {
return oldValue;
}
public Object getSource() {
return source;
}
}
public interface ClicCase {
public void clic(ClicEvent cv);
}
1 / 3 100%
La catégorie de ce document est-elle correcte?
Merci pour votre participation!

Faire une suggestion

Avez-vous trouvé des erreurs dans linterface ou les textes ? Ou savez-vous comment améliorer linterface utilisateur de StudyLib ? Nhésitez pas à envoyer vos suggestions. Cest très important pour nous !