[] STUDY ³»¿ë

ÀÛ¼ºÀÏ 2004-04-07
ÀÛ¼ºÀÚ park
Á¶È¸¼ö 1279
Á¦ ¸ñ Ŭ¶óÀ̾ðÆ®ÀÇ ÇöÀç ¸¶¿ì½º ÁÂÇ¥ ¼ÛÃâ(Ŭ¶óÀ̾ðÆ®)

¸ñ·ÏÀ¸·Î | ¼öÁ¤ | »èÁ¦ | Á¤º¸Ãß°¡[reply] | ½Å±ÔÀÔ·Â

//  mousePositionClient
//  ÇöÀç  ¸¶¿ì½º  ÁÂÇ¥°ª  ¼ÛÃâÇϱâ

import  java.awt.*;
import  java.io.*;
import  java.awt.event.*;
import  java.net.*;

class  mousePositionClient  extends  Frame  implements  ActionListener,  KeyListener,  MouseMotionListener
{
    myWindowAdater  myW  =  new  myWindowAdater();  //  WindowListener  ->  WindowAdpater»ç¿ë
    
    Panel  topP  =  new  Panel();
    Panel  centerP  =  new  Panel();
    Panel  bottomP  =  new  Panel();
    
    //  Stream
    InputStream  input;
    InputStreamReader  reader;
    BufferedReader  receive;
    
    OutputStream  output;
    OutputStreamWriter  writer;
    PrintWriter  send;
    
    //  Socket
    Socket  s;
    
    //  top
    Label  ipLabel  =  new  Label("IP  Address");
    Label  portLabel  =  new  Label("Port  Number");
    TextField  ip  =  new  TextField("localhost");
    TextField  port  =  new  TextField("4444");
    Button  connectButton  =  new  Button("Connect");
    
    //  bottom
    TextField  talk  =  new  TextField();
    Button  sendButton  =  new  Button("Send");
    
    public  mousePositionClient()
    {
        setTitle("Client");
        setLayout(null);
        addWindowListener(myW);
        
        //  top  Panel
        topP.setLayout(null);
        topP.setBackground(Color.blue);
        topP.setBounds(5,30,340,50);
        
        ipLabel.setBounds(0,0,75,20);
        ipLabel.setAlignment(Label.RIGHT);
        topP.add(ipLabel);
        ip.setBounds(80,0,150,20);
        topP.add(ip);
        
        portLabel.setBounds(0,25,75,20);
        topP.add(portLabel);
        port.setBounds(80,25,150,20);
        topP.add(port);
        
        connectButton.setBounds(245,0,70,45);
        connectButton.addActionListener(this);  //  connecting...
        topP.add(connectButton);
        
        add(topP);
        
        //  center  Panel
        centerP.setLayout(new  BorderLayout());
        centerP.setBounds(5,81,340,370);
        centerP.setBackground(new  Color(200,100,100));
        centerP.addMouseMotionListener(this);
        
        add(centerP);
        
        //  bottom
        bottomP.setBounds(5,452,340,23);
        bottomP.setLayout(null);
        talk.setBounds(0,0,280,22);
        talk.addKeyListener(this);  //  KeyListener  ....
        bottomP.add(talk);
        
        sendButton.setBounds(285,0,50,22);
        sendButton.addActionListener(this);  //  ActionListener  ....
        bottomP.add(sendButton);
        
        add(bottomP);
        
    }
    
    public  void  connectProcess()  
    {
        try
        {
            s  =  new  Socket(ip.getText(),  Integer.parseInt(port.getText()));
            input  =  s.getInputStream();
            reader  =  new  InputStreamReader(input);
            receive  =  new  BufferedReader(reader);
            
            output  =  s.getOutputStream();
            writer  =  new  OutputStreamWriter(output);
            send  =  new  PrintWriter(writer);
            connectButton.setEnabled(false);
        }catch(Exception  e){}
    }
    
    public  void  sendProcess()
    {
        send.println(talk.getText());
        send.flush();
        talk.setText("");
    }
    
    //  actionLister  Method  (  connectButton  and  sendButton)
    public  void  actionPerformed(ActionEvent  e)  
    {
        if(e.getSource().equals(connectButton))  //  ¿¬°á  Ã³¸®
        {
            connectProcess();
        }
        
        if(e.getSource().equals(sendButton))  //  ¸Þ½ÃÁö  Àü¼Û  Ã³¸®
        {
            sendProcess();
        }
    }
    
    //  keylistener  method
    public  void  keyTyped(KeyEvent  e)
    {
    }
    
    //  TextFieldâ¿¡¼­  ¿£ÅÍÅ°¸¦  ´©¸£¸é  Ã³¸®.
    public  void  keyPressed(KeyEvent  e)
    {
        if(e.getKeyCode()  ==  KeyEvent.VK_ENTER)  sendProcess();
    }
    
    public  void  keyReleased(KeyEvent  e)
    {
    }
    
    //  MouseMotionLisener
    public  void  mouseDragged(MouseEvent  e)
    {
        String  str  =  "Position  :  ("  +  e.getX()  +  "  ,  "    +  e.getY()  +  ")";
        send.println(str);
        send.flush();
    }
    
    
    //  MouseListener
    public  void  mouseClicked(MouseEvent  e)
    {
    }
    
    public  void  mouseMoved(MouseEvent  e)
    {
    }
    
    public  void  mousePressed(MouseEvent  e)
    {
    }
    
    public  void  mouseReleased(MouseEvent  e)
    {
    }
    public  void  mouseEntered(MouseEvent  e)
    {
    }
    public  void  mouseExited(MouseEvent  e)
    {
    }
    
    
    //  WindowAdapter
    class  myWindowAdater  extends  WindowAdapter
    {
        public  void  windowClosing(WindowEvent  e)
        {
            dispose();
            System.exit(0);
        }
    }
    
    public  static  void  main(String  args[])
    {
        mousePositionClient  c  =  new  mousePositionClient();
        c.setSize(350,480);
        c.setVisible(true);
    }

}

Ŭ¶óÀ̾ðÆ®ÀÇ ÇöÀç ¸¶¿ì½º ÁÂÇ¥ ¼ÛÃâ(Ŭ¶óÀ̾ðÆ®) °ú(¿Í) °ü·ÃµÈ Ãß°¡ Á¤º¸

  • Ŭ¶óÀ̾ðÆ®ÀÇ ÇöÀç ¸¶¿ì½º ÁÂÇ¥ ¼ÛÃâ(¼­¹ö) [2004-04-07] [park´Ô Àç°ø] [Á¶È¸:928]
  • Ŭ¶óÀ̾ðÆ®ÀÇ ÇöÀç ¸¶¿ì½º ÁÂÇ¥ ¼ÛÃâ(Ŭ¶óÀ̾ðÆ®) [2004-04-07] [park´Ô Àç°ø] [Á¶È¸:1279]
  • °¡Àå °£´ÜÇÑ ¼ÒÄÏ ¼­¹ö¿Í Ŭ¶óÀ̾ðÆ® [2003-11-27] [park´Ô Àç°ø] [Á¶È¸:987]
  • ¼ÒÄÏÀ» È°¿ëÇÑ ½Ç½Ã°£ ¸Þ½ÃÁö Àü´Þ ¼­ºñ½º [2003-12-03] [park´Ô Àç°ø] [Á¶È¸:2458]
  • ¼ÒÄÏÀ» »ç¿ëÇÑ °£´ÜÇÑ Ã¤Æà [2003-12-05] [park´Ô Àç°ø] [Á¶È¸:1777]

    ¸ñ·ÏÀ¸·Î | ¼öÁ¤ | »èÁ¦ | Á¤º¸Ãß°¡[reply] | ½Å±ÔÀÔ·Â