|
이전 질문 게시판은 새 글 쓰기를 막았습니다. [질문 게시판]을 이용바랍니다.
Date |
2011/11/05 02:39:47 |
Name |
SaMid |
Subject |
자바 질문있습니다. |
이 코드를 실행시키면 처음에 두 화면으로 분할이 되는데요,
예를 들어 같은 폴더안에 img 라는 jpg파일이 있다고 하면 아부분에 img 파일을 삽입키고 싶은데 어떻게 수정해야하나요?
계속 찾아보면서 하고 있는데 스윙은 처음이라 감이 잘 안잡히네요...
아래는 코드입니다.
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import javax.imageio.ImageIO;
import javax.swing.*;
public class WinChatClient extends Frame implements ActionListener {
private TextField idTF = null;
private TextField input = null;
private TextArea display = null;
private CardLayout cardLayout = null;
private BufferedReader br = null;
private PrintWriter pw = null;
private Socket sock = null;
public WinChatClient(String ip) {
super("Restaurant Monitor");
cardLayout = new CardLayout();
setLayout(cardLayout);
Panel loginPanel = new Panel();
loginPanel.setLayout(new BorderLayout());
/*mFile.setFont(new Font("궁서",Font.PLAIN,12)); */
loginPanel.setFont(new Font("굴림", Font.PLAIN, 16)); //글씨변경
loginPanel.setBackground(Color.white); //배경색 변경(위쪽)
loginPanel.add("North", new Label("아이디를 입력하세요."));
idTF = new TextField(20);
idTF.addActionListener(this);
Panel c = new Panel();
c.add(idTF);
c.setBackground(Color.LIGHT_GRAY);//로긴화면 아랫부분 색깔
loginPanel.add("Center", c);
add("login", loginPanel);
// c.add(this, "center");
Panel main = new Panel();
main.setFont(new Font("Arial", Font.BOLD, 30));
main.setForeground(Color.DARK_GRAY);// 내용 색상(본문 색상 변환)
/*Font font = new Font ( "Verdana" , Font . BOLD , 12 ) ;
txt. setFont (font); txt. setFont ( font ) ;
txt. setForeground ( Color . BLUE); txt. setForeground ( Color . BLUE ) */
//main.setBackground((Color.pink));
main.setLayout(new BorderLayout());
input = new TextField();
input.addActionListener(this);
display = new TextArea();
display.setEditable(false);
main.add("Center", display);
main.add("South", input);
add("main", main);
try {
sock = new Socket("ip", 10001);
pw = new PrintWriter(new OutputStreamWriter(sock.getOutputStream()));
br = new BufferedReader(new InputStreamReader(sock.getInputStream()));
} catch(Exception ex) {
System.out.println("서버와 접속시 오류가 발생하였습니다.");
System.out.println(ex);
System.exit(1);
}
setSize(500, 500);
cardLayout.show(this, "login");
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
pw.println("/quit");
pw.flush();
try {
sock.close();
} catch(Exception ex) {}
System.out.println("종료합니다.");
System.exit(0);
}
});
setVisible(true);
}
public static void main(String[] args) {
if(args.length != 1) {
System.out.println("사용법 : java WinChatClient ip");
System.exit(1);
}
new WinChatClient(args[0]);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == idTF) {
String id = idTF.getText();
if(id == null || id.trim().equals("")) {
System.out.println("아이디를 다시 입력하여 주세요.");
return;
}
pw.println(id.trim());
pw.flush();
WinInputThread wit = new WinInputThread(sock, br);
wit.start();
cardLayout.show(this, "main");
input.requestFocus();
} else if(e.getSource() == input) {
String msg = input.getText();
pw.println(msg);
pw.flush();
if(msg.equals("/quit")) {
try {
sock.close();
} catch(Exception ex) {}
System.out.println("종료합니다.");
System.exit(1);
}
input.setText("");
input.requestFocus();
}
}
class WinInputThread extends Thread {
private Socket sock = null;
private BufferedReader br = null;
public WinInputThread(Socket sock, BufferedReader br) {
this.sock = sock;
this.br = br;
}
public void run() {
try {
String line = null;
while((line = br.readLine()) != null) {
display.append(line + "\n");
}
} catch(Exception ex) {
} finally {
try {
if(br != null)
br.close();
} catch(Exception ex) {}
try {
if(sock != null)
sock.close();
} catch(Exception ex) {}
}
}
}
}
|
통합규정 1.3 이용안내 인용
"Pgr은 '명문화된 삭제규정'이 반드시 필요하지 않은 분을 환영합니다.
법 없이도 사는 사람, 남에게 상처를 주지 않으면서 같이 이야기 나눌 수 있는 분이면 좋겠습니다."
|