private void setupUsernameRequestView() { PANEL = new JPanel(); PANEL.setBackground(Color.BLACK); userName = new CstmTextField("", "Enter your name"); enter = new CstmButton("ENTER"); userNameLabel = new CstmLabel("USER NAME", SwingConstants.CENTER); serverTalkLabel = new CstmLabel("", SwingConstants.CENTER); PANEL.setLayout(new BoxLayout(PANEL, BoxLayout.Y_AXIS)); userName.setPreferredSize(new Dimension(200, 30)); userName.setAlignmentX(Component.CENTER_ALIGNMENT); enter.setPreferredSize(new Dimension(200, 30)); enter.setAlignmentX(Component.CENTER_ALIGNMENT); serverTalkLabel.setPreferredSize(new Dimension(450, 30)); serverTalkLabel.setAlignmentX(Component.CENTER_ALIGNMENT); enter.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { CHAT_CLIENT.chatNameRequest(userName.getText().trim()); } }); userNameLabel.setAlignmentX(Component.CENTER_ALIGNMENT); PANEL.add(userNameLabel); PANEL.add(userName); PANEL.add(enter); PANEL.add(serverTalkLabel); Container container = getContentPane(); container.setLayout(new GridBagLayout()); container.add(PANEL, new GridBagConstraints()); container.setBackground(Color.BLACK); pack(); setVisible(true); }
@Override public void notice(String notice) { if (USERNAME == null) { serverTalkLabel.setText(notice); } consolePanel.p(notice); }
@Override public void nameRequestResponse(String name, String response) { if (name == null) serverTalkLabel.setText(response); else { USERNAME = name; setTitle("Peep Chat : " + name); setupActualChatView(); } }