java中如何用鼠标单击事件连接客户端
程序代码:
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); c5.addMouseListener(new MouseAdapter(){ @Override public void mouseClicked(MouseEvent e) { System.out.println("投票开始"); String host ="172.16.229.90"; int port = 8006; try { Socket client=new Socket(host,port); Writer writer=new OutputStreamWriter(client.getOutputStream()); writer.flush(); writer.close(); client.close(); } catch (UnknownHostException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } // TODO Auto-generated method stub } }); c1.addMouseListener(new MouseAdapter(){ @Override public void mouseClicked(MouseEvent e) { // TODO Auto-generated method stub } }); c2.addMouseListener(new MouseAdapter(){ @Override public void mouseClicked(MouseEvent e) { //System.out.println("投票成功"); // TODO Auto-generated method stub } }); c3.addMouseListener(new MouseAdapter(){ @Override public void mouseClicked(MouseEvent e) { //System.out.println("投票成功"); // TODO Auto-generated method stub } }); c4.addMouseListener(new MouseAdapter(){ @Override public void mouseClicked(MouseEvent e) { //System.out.println("投票成功"); // TODO Auto-generated method stub } }); }
请问这里的鼠标事件怎么连接到客户端,我想做一个投票器。