public MotionSensor( String title, float winPosX, float winPosY, final MessageManagerInterface em) { mw = new MessageWindow(title, winPosX, winPosY); JButton button = new JButton(); button.setText("Motion Sensor"); button.setEnabled(true); button.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { Message msg = new Message(Configuration.MOTION_SENSOR_ID, "WB"); // Here we send the message to the message manager. try { em.SendMessage(msg); mw.WriteMessage("Detected Motion!"); } // try catch (Exception e) { System.out.println("Motion Sensor Error:: " + e); } // catch } }); JFrame buttonFrame = new JFrame(); buttonFrame.setBounds(mw.GetX(), mw.GetY(), 50, 80); buttonFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); JPanel buttonPanel = new JPanel(); buttonFrame.add(buttonPanel); buttonPanel.add(button); buttonFrame.setVisible(true); }