private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jMenuItem1ActionPerformed

		final String inputValue = JOptionPane
				.showInputDialog("Enter a chatroom name");
		//final JTextArea textArea = new JTextArea();
		final JButton btnClose = new JButton("x");
		if (inputValue.isEmpty()) {
			JOptionPane.showMessageDialog(GUI.this, "Please enter a name.",
					"Input Error", JOptionPane.WARNING_MESSAGE);
		} else {

			try {
				client.sendJoinChatRoomMessage(inputValue);
			} catch (JMSException e) {
				throw new RuntimeException(e);
			}

			ChatClientApplicationGUI
					.addServerMessageListener(new ServerMessageListener() {

						public void onMessageReceived(ChatMessage m) {
							if (!(m instanceof ChatRoomUsersMessage))
								return;

							final ChatRoomUsersMessage ulm = (ChatRoomUsersMessage) m;

							if (ulm.getChatRoom().equals(
									tabbedPane.getTitleAt(tabbedPane
											.getSelectedIndex()))) {

								userList.setModel(new javax.swing.AbstractListModel() {
									List<String> strings = ulm.getUsers();

									public int getSize() {
										return strings.size();
									}

									public Object getElementAt(int i) {
										return strings.get(i);
									}
								});
							}
						}
					});

			ChatClientApplicationGUI
					.addServerMessageListener(new ServerMessageListener() {

						public void onMessageReceived(ChatMessage m) {
							if (!(m instanceof JoinChatRoomMessage))
								return;

							try {
								client.sendChatRoomUserListMessage(inputValue);
							} catch (JMSException e) {
								throw new RuntimeException(e);
							}
							final JTextArea jta = new JTextArea();
							tabbedPane.addTab(inputValue, null, jta, null);

							ChatClientApplicationGUI
									.addServerMessageListener(new ServerMessageListener() {

										public void onMessageReceived(
												ChatMessage m) {
											if (!(m instanceof ChatTextMessage))
												return;
											final ChatTextMessage ulm = (ChatTextMessage) m;
											
											jta.append("[" + ulm.getUsername() + "]: " + ulm.getText()+ "\n");
											
										}
									});

							int index = tabbedPane.indexOfTab(inputValue);
							JPanel pnlTab = new JPanel();
							pnlTab.setOpaque(false);
							JLabel lblTitle = new JLabel(inputValue);

							pnlTab.add(lblTitle);
							pnlTab.add(btnClose);

							tabbedPane.setTabComponentAt(index, pnlTab);

							btnClose.addActionListener(new java.awt.event.ActionListener() {
								public void actionPerformed(
										java.awt.event.ActionEvent evt) {
									btnCloseActionPerformed(evt);
								}

								private void btnCloseActionPerformed(
										ActionEvent evt) {
									Point mousePos = tabbedPane
											.getMousePosition();
									int mouseX = mousePos.x;
									int mouseY = mousePos.y;
									int index = tabbedPane.indexAtLocation(
											mouseX, mouseY);
									Component selected = tabbedPane
											.getComponentAt(index);
									if (selected != null) {
										tabbedPane.remove(selected);
									}
								}
							});
							//tabbedPane.setSelectedComponent(textArea);
							jta.append("[System]: Joined " + inputValue
									+ "\n");

							ChatClientApplicationGUI.removeServerMessageListener(this);
						}
						
					});
		}
	}