import javax.swing.*; import java.awt.*; //import AWTBPEvents.*; import NonAWTBPEvents.*; /** * This class implements a JPanel that monitors a patient's * blood pressure. It handles the blood pressure events * generated by a patient. * * @author Stuart Hansen * @version February 2009 */ public class BloodPressurePanel extends JPanel implements BloodPressureListener { JLabel systolicLabel; // label displaying the systolic bp JLabel diastolicLabel; // label displaying the diastolic bp // The constructor lays things out in the GUI public BloodPressurePanel () { systolicLabel = new JLabel(); systolicLabel.setBounds(20, 20, 250, 30); diastolicLabel = new JLabel(); diastolicLabel.setBounds(20, 60, 250, 30); setSize(300, 150); setPreferredSize(new Dimension(300, 150)); setLayout(null); add(systolicLabel); add(diastolicLabel); } // Set the text in the systolicLabel public void setSystolicDisplay (int systolic) { systolicLabel.setText ("The systolic blood pressure is: " + systolic); } // Set the text in the diastolicLabel public void setDiastolicDisplay (int diastolic) { diastolicLabel.setText ("The diastolic blood pressure is: " + diastolic); } // receives the event if the upper value (systolic) changes public void systolicChange(BloodPressureEvent e) { int systolic = e.getValue(); setSystolicDisplay(systolic); } // receives the event if the upper value (systolic) changes public void diastolicChange(BloodPressureEvent e) { int diastolic = e.getValue(); setDiastolicDisplay(diastolic); } // Processes warning events when systolic is too extreme /* public void warning (BloodPressureEvent e) { Patient patient = (Patient) e.getSource(); // This sleep demonstrates what can happen if a handler // runs too long. The GUI gets bogged down. try {Thread.sleep(10000);} catch (Exception ex){}; JOptionPane.showMessageDialog( null, "WARNING! Patient " + patient.getName() + " has systolic pressure of: " + e.getValue()); }*/ // Processes warning events in a new thread public void warning (BloodPressureEvent e) { new Thread(new Warner(e)).start(); } // We use a class implementing the Runnable interface // to run the handler code in a new thread private class Warner implements Runnable { BloodPressureEvent e; public Warner (BloodPressureEvent e) { this.e = e; } // The thread's start method calls run public void run() { Patient patient = (Patient) e.getSource(); try{Thread.sleep(10000);}catch(Exception ex){}; JOptionPane.showMessageDialog( null, "WARNING! Patient " + patient.getName() + " has systolic pressure of: " + e.getValue()); } } }