1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| class ChatPanel extends JPanel {
JTextField chatTextField;
JScrollPane scroll;
ChatPanel() {
JPanel contentchat = new JPanel();
chatTextField = new JTextField("Ecrire ici");
chatTextField.setPreferredSize(new Dimension(787, 27));
Font fontchatTextField = new Font("Arial",Font.BOLD,14);
chatTextField.setFont(fontchatTextField);
chatTextField.setForeground(new Color(10,140,242));
JButton envoyerBouton = new JButton("Envoyer");
envoyerBouton.setBackground(new Color(255,112,0));
envoyerBouton.setForeground(new Color(255,255,255));
setLayout(new BorderLayout());
contentchat.add(chatTextField);
contentchat.add(envoyerBouton);
add(contentchat, BorderLayout.SOUTH);
//textArea.append(chatLabel);
//chatTextField.selectAll();
textArea = new JTextArea("Bienvenue dans le chat !" + "\n");
Font fontarea = new Font("Arial",Font.BOLD,14);
textArea.setFont(fontarea);
textArea.setForeground(new Color(10,140,242));
textArea.setEditable(false);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
add(textArea, BorderLayout.NORTH);
JScrollPane scroll = new JScrollPane(textArea);
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scroll.setPreferredSize(new Dimension(800, 600));
add(scroll);
envoyerBouton.addActionListener(new envoyerBoutonListener());
goo();
}
private void goo(){
}
class envoyerBoutonListener implements ActionListener{
public void actionPerformed(ActionEvent arg0) {
recupChatTextField = chatTextField.getText();
String chatLabel = ("\n" + "Vous : " + recupChatTextField);
textArea.append(chatLabel);
textArea.revalidate();
}
}
} |
Partager