Repository navigation
Expand file tree
/
Copy pathChatProgram.txt
More file actions
117 lines (93 loc) · 2.7 KB
/
Copy pathChatProgram.txt
File metadata and controls
117 lines (93 loc) · 2.7 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package swing.test;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class ChatProgram extends JFrame implements ActionListener {
private JButton btnStart;
private ChatProgram2 c2;
private JTextField tf;
private JTextArea ta;
private JButton btnSend;
public ChatProgram(String title) {
setTitle(title);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 500);
setLocation(800, 300);
setLayout(new FlowLayout());
setResizable(false);
Container cp = getContentPane();
cp.setBackground(Color.LIGHT_GRAY);
NorthPane();
CenterPane();
SouthPane();
setVisible(true);
}
private void SouthPane() {
JPanel paneSouth = new JPanel();
tf = new JTextField(20);
tf.addActionListener(this);
paneSouth.add(tf);
btnSend = new JButton("보내기");
btnSend.addActionListener(this);
btnSend.setPreferredSize(new Dimension(100,30));
paneSouth.add(btnSend);
add(paneSouth, BorderLayout.SOUTH);
}
private void CenterPane() {
JPanel paneCenter = new JPanel();
ta = new JTextArea(22, 32);
ta.setLineWrap(true);
ta.setEditable(false);
JScrollPane sp = new JScrollPane(ta, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
paneCenter.add(sp);
add(paneCenter, BorderLayout.CENTER);
}
private void NorthPane() {
JPanel paneNorth = new JPanel();
JLabel label = new JLabel("채팅을 시작하려면 시작버튼을 누르세요.");
paneNorth.add(label);
btnStart = new JButton("시작");
btnStart.addActionListener(this);
paneNorth.add(btnStart);
add(paneNorth, BorderLayout.NORTH);
}
public static void main(String[] args) {
new ChatProgram("ChatProgram");
}
@Override
public void actionPerformed(ActionEvent e) {
Object obj = e.getSource();
if(obj == btnStart) {
c2 = new ChatProgram2("ChatProgram2", 1200, 300, this);
} else if(!tf.getText().equals("")) {
if(c2 != null ) {
ta.append("[김용진] : " + tf.getText() + "\n");
String str = ta.getText();
c2.getTa().setText(str);
} else {
JOptionPane.showMessageDialog(this, "채팅 프로그램을 먼저 시작하세요.",
"경고", JOptionPane.WARNING_MESSAGE);
}
}
tf.setText("");
}
public JTextArea getTa() {
return ta;
}
public void setTa(JTextArea ta) {
this.ta = ta;
}
}