JAVA 채팅 Client 예제 #1

Programming/JAVA,JSP 2014. 1. 20. 17:27 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

import java.awt.BorderLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.IOException;

import java.io.PrintWriter;

import java.net.Socket;

import java.net.UnknownHostException;

import java.util.Scanner;


import javax.swing.JFrame;

import javax.swing.JTextArea;

import javax.swing.JTextField;




public class Client {

static JTextField textField;

static JTextArea textArea;

static PrintWriter out;

public static void main(String[] args) {

try {

Socket s = new Socket("115.20.247.170",5555);


out = new PrintWriter(s.getOutputStream(), true);


JFrame f = new JFrame("채팅");

f.setSize(600, 400);

f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);

textArea = new JTextArea();

textField = new JTextField(10);

textField.addActionListener(


new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

out.println(textField.getText());

}

}

);

f.add(textField, BorderLayout.SOUTH);

f.add(textArea , BorderLayout.CENTER);

f.setVisible(true);

} catch (UnknownHostException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}



'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA 채팅 예제 #2  (0) 2014.01.20
JAVA 채팅 Server 예제 #1  (0) 2014.01.20
JAVA FIle 실습 #1  (0) 2014.01.17
JAVA File 실습  (0) 2014.01.17
JAVA 공던지기 게임 완성  (0) 2014.01.16