|
¸ñ·ÏÀ¸·Î | ¼öÁ¤ | »èÁ¦ | Á¤º¸Ãß°¡[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); } } |
¸ñ·ÏÀ¸·Î | ¼öÁ¤ | »èÁ¦ | Á¤º¸Ãß°¡[reply] | ½Å±ÔÀÔ·Â |