-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatWindow.java
More file actions
37 lines (29 loc) · 882 Bytes
/
ChatWindow.java
File metadata and controls
37 lines (29 loc) · 882 Bytes
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
import javax.swing.*;
import java.awt.*;
/**
* YOUR NAME HERE
*/
public class ChatWindow extends JFrame {
private JTextArea textArea;
protected Container contentPane;
public ChatWindow() {
textArea = new JTextArea();
textArea.setEditable(false);
textArea.setLineWrap(true);
textArea.setColumns(55);
contentPane = this.getContentPane();
this.setSize(400, 400);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JScrollPane textScroller = new JScrollPane(textArea);
textScroller.setPreferredSize(new Dimension(400, 400));
contentPane.add(textScroller);
this.setLocation(500, 80);
this.setVisible(true);
this.setTitle("Chat Window");
}
/** Append a message to the text area and then scroll down so it is visible */
public void printMsg(String s) {
textArea.append(s + "\n");
textArea.setCaretPosition(textArea.getText().length());
}
}