/** * Constructs a new ChatChannelFrame as a wrapper around the given channel. * * @param client the parent {@code ChatClient} of this frame. * @param channel the channel that this class will manage. */ public ChatChannelFrame(ChatClient client, ClientChannel channel) { super("Channel: " + channel.getName()); myChatClient = client; myChannel = channel; Container c = getContentPane(); c.setLayout(new BorderLayout()); JPanel eastPanel = new JPanel(); eastPanel.setLayout(new BorderLayout()); c.add(eastPanel, BorderLayout.EAST); eastPanel.add(new JLabel("Users"), BorderLayout.NORTH); memberList = new MemberList(); memberList.addMouseListener(myChatClient.getDCCMouseListener()); eastPanel.add(new JScrollPane(memberList), BorderLayout.CENTER); JPanel southPanel = new JPanel(); c.add(southPanel, BorderLayout.SOUTH); southPanel.setLayout(new GridLayout(1, 0)); inputField = new JTextField(); southPanel.add(inputField); outputArea = new JTextArea(); c.add(new JScrollPane(outputArea), BorderLayout.CENTER); inputField.addActionListener(this); setSize(400, 400); setClosable(true); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); addInternalFrameListener(new FrameClosingListener(this)); setResizable(true); setVisible(true); }
/** * {@inheritDoc} * * <p>Broadcasts on this channel the text entered by the user. */ public void actionPerformed(ActionEvent action) { try { byte[] contents = inputField.getText().getBytes(); byte[] message = ChatClient.getMessage(OP_MESSAGE, contents); myChannel.send(message); } catch (IOException e) { e.printStackTrace(); } inputField.setText(""); }