import javax.swing.*; import javax.swing.event.*; //import AWTBPEvents.Patient; import NonAWTBPEvents.*; import java.awt.event.*; /** This class wraps a Patient object with a GUI representation that allows * us to dynamically set the blood pressure. * * @author Stuart Hansen * @version February 2009 */ public class PatientPanel extends JPanel{ private Patient patient; // Our patient private JLabel sysLabel; // Label for systolic slider private JLabel diaLabel; // Label for diastoloic slider private JSlider sysSlider; // Slider to set systolic pressure private JSlider diaSlider; // Label to set diastolic pressure // The constructor requires a patient public PatientPanel (Patient pat) { super(); patient = pat; // Set up the GUI sysLabel = new JLabel("Systolic Pressure"); add(sysLabel); sysSlider = new JSlider(0, 250, patient.getSystolic()); sysSlider.setLabelTable(sysSlider.createStandardLabels(50)); sysSlider.setPaintLabels(true); sysSlider.setMajorTickSpacing(50); sysSlider.setPaintTicks(true); sysSlider.addChangeListener(new SystolicHandler()); add(sysSlider); diaLabel = new JLabel("Diastolic Pressure"); add(diaLabel); diaSlider = new JSlider(0, 250, patient.getDiastolic()); diaSlider.setLabelTable(diaSlider.createStandardLabels(50)); diaSlider.setPaintLabels(true); diaSlider.setMajorTickSpacing(50); diaSlider.setPaintTicks(true); diaSlider.addChangeListener(new DiastolicHandler()); add(diaSlider); setSize(300, 200); } // We handle changes in the panel by calling setters // in the patient // Handle the systolic slider private class SystolicHandler implements ChangeListener { public void stateChanged (ChangeEvent e) { patient.setSystolic(sysSlider.getValue()); } } // Handle the diastolic slider private class DiastolicHandler implements ChangeListener { public void stateChanged (ChangeEvent e) { patient.setDiastolic(diaSlider.getValue()); } } }