public static void main(String[] args) {
new VerySimpleChatServer().start();
}
public void start() {
JFrame frame = new JFrame("server status");
JPanel mainPanel = new JPanel();
status = new JTextArea(15,40);
status.setLineWrap(true); //자동 개행
status.setWrapStyleWord(true); //행을 넘길 때 행의 마지막 단어가 두행에 걸쳐 나뉘지 않도록 하기
status.setEditable(false);
status.setVisible(true);
JButton exitButton = new JButton("Exit");
exitButton.addActionListener(new ExitButtonListener());
JScrollPane qScroller = new JScrollPane(status);
qScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); //수직 스크롤바 표시 정책 : 항상 보여주기
qScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);// 수평 스크롤바 표시 정책 : 항상 보여주기
mainPanel.add(qScroller);
mainPanel.add(exitButton);
status.append("Chat Server Start..\n");
JTextArea incoming; // 서버로부터 읽어온 메시지를 표시할 영역
JTextField outgoing; // 서버로보낼 메시지를 입력할 영역
BufferedReader reader; // 서버로부터 온 메시지를 읽어드릴 읽기버퍼
PrintWriter writer; // 메시지를 소켓 스트림에 써줄 쓰기 스트림
Socket sock; // 소켓
public static void main(String[] args) {
SimpleChatClient client = new SimpleChatClient();
client.go();
}
public void go() {
// 채팅창 UI
JFrame frame = new JFrame("Ludicrously Simple Chat Client");
JPanel mainPanel = new JPanel();
incoming = new JTextArea(15,40);
incoming.setLineWrap(true); //자동 개행
incoming.setWrapStyleWord(true); // 행을 넘길 때 행의 마지막 단어가 두행에 걸쳐 나뉘지 않도록 하기
incoming.setEditable(false);
incoming.setVisible(true);
JScrollPane qScroller = new JScrollPane(incoming);
qScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); //수직 스크롤바 표시 정책 : 항상 보여주기
qScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);// 수평 스크롤바 표시 정책 : 항상 보여주기
outgoing = new JTextField(20);
JButton sendButton = new JButton("Send");
sendButton.addActionListener(new SendButtonListener());
JButton exitButton = new JButton("Exit");
exitButton.addActionListener(new ExitButtonListener());
mainPanel.add(qScroller);
mainPanel.add(outgoing);
mainPanel.add(sendButton);
mainPanel.add(exitButton);
incoming.append("notice : UI 초기화\n");
// 소켓 통신 초기화
setUpNetWorking();
incoming.append("notice : 소켓 통신 초기화\n");
incoming.append("notice : 채팅에 입장하셨습니다.\n\n");
// 읽기 쓰레드 생성, 시작
Thread readerThread = new Thread(new IncomingReader());
readerThread.start();
// UI visual(정렬,크기) 설정
frame.getContentPane().add(BorderLayout.CENTER, mainPanel);
frame.setSize(500, 500);
frame.setVisible(true);
}