/** * * Program SampleEventListener.java * * Author Tomomi Kawashima * * Date 2003/10/06 * * This class is a event listener. This class listen a event of sample tab and send it * to other peer in a same room as a message. * */ package tomscop.application.sample; import java.awt.Color; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import tomscop.SMT.RoomMsgSender; import tomscop.util.DefinitionUtilities; import tomscop.util.PeerUtilities; import tomscop.util.RoomUtilities; public class SampleEventListener implements ActionListener { private RoomMsgSender roommsgsender = new RoomMsgSender(); private PeerUtilities peerutilities = PeerUtilities.getInstance(); private RoomUtilities roomutilities = RoomUtilities.getInstance(); private SampleUtilities utilities = SampleUtilities.getInstance(); public void actionPerformed( ActionEvent e ) { // if peer push red button if(e.getSource() == utilities.getRedButton()) { // set background red utilities.getCanvasPanel().setBackground(Color.WHITE); // if peer belong a room if(roomutilities.isRoomPipeExist()) { // send message roommsgsender.sendRoomMsg(DefinitionUtilities.SAMPLE, SampleUtilities.WHITE, peerutilities.getPeerName()); } } // if peer push blue button else if(e.getSource() == utilities.getBlueButton()) { // set background blue utilities.getCanvasPanel().setBackground(Color.BLUE); if(roomutilities.isRoomPipeExist()) { // send message roommsgsender.sendRoomMsg(DefinitionUtilities.SAMPLE, SampleUtilities.BLUE, peerutilities.getPeerName()); } } // event catch at the text field else if(e.getSource() == utilities.getInputField()) { // get text from inputField String message = utilities.getInputField().getText(); // set text at messageLabel utilities.getMessageLabel().setText(" <" + peerutilities.getPeerName() + "> " + message); // set inputField to empty utilities.getInputField().setText(""); // if peer belong a room if(roomutilities.isRoomPipeExist()) { // send message roommsgsender.sendRoomMsg( DefinitionUtilities.SAMPLE, SampleUtilities.MESSAGE, peerutilities.getPeerName(), message); } } } }