@Override
 public void windowClosing(WindowEvent e) {
   System.out.println("Disconnecting from server...");
   client.disconnect();
   System.exit(0);
 }
  private void createAndShowGUI() {
    String username =
        JOptionPane.showInputDialog(
            frame,
            "Enter your username here:",
            "Shared Telepointer Client",
            JOptionPane.PLAIN_MESSAGE);

    // enable anti-aliased text:
    System.setProperty("awt.useSystemAAFontSettings", "on");
    System.setProperty("swing.aatext", "true");
    frame = new JFrame(username);
    hideCursor();

    client = new SharedPointerClient(this);
    client.connect("localhost", username);

    glassPane = new PointerGlassPane(frame, client.model, new OvalDrawer(0.5f, 10));
    glassPane.addTelepointerEventListener(this);
    frame.setGlassPane(glassPane);
    glassPane.setVisible(true);

    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("View");
    menu.setMnemonic(KeyEvent.VK_V);
    menuBar.add(menu);

    final JCheckBoxMenuItem menuItem1 = new JCheckBoxMenuItem("Show Telepointers");
    menuItem1.setSelected(true);
    menuItem1.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent ae) {
            if (menuItem1.isSelected()) {
              glassPane.setVisible(true);
              hideCursor();
            } else {
              glassPane.setVisible(false);
              showCursor();
            }
          }
        });
    menu.add(menuItem1);

    final JCheckBoxMenuItem menuItem2 = new JCheckBoxMenuItem("Enable Telepointer");
    menuItem2.setSelected(true);
    menuItem2.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent ae) {
            if (menuItem2.isSelected()) {
              client.enablePointer();
              hideCursor();
            } else {
              client.disablePointer();
              showCursor();
            }
          }
        });
    menu.add(menuItem2);

    final JCheckBoxMenuItem menuItem3 = new JCheckBoxMenuItem("Draw mouse icons");
    menuItem3.setSelected(false);
    menuItem3.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent ae) {
            if (menuItem3.isSelected()) {
              glassPane.setDrawer(new MouseIconDrawer());
            } else {
              glassPane.setDrawer(new OvalDrawer(0.5f, 10));
            }
          }
        });
    menu.add(menuItem3);

    frame.setJMenuBar(menuBar);

    try {
      BufferedReader r = new BufferedReader(new FileReader("view/sample.txt"));
      String line, contents = "";
      while ((line = r.readLine()) != null) {
        contents += line + "\r\n";
      }
      r.close();
      JEditorPane editorPane = new JEditorPane("text/text", contents);
      editorPane.setFont(new Font("Monaco", Font.PLAIN, 12));
      frame.getContentPane().add(editorPane);
      editorPane.setEditable(false);
    } catch (IOException e) {
      e.printStackTrace();
    }

    frame.addWindowListener(this);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setMinimumSize(new Dimension(480, 400));
    frame.setLocation(200, 80);
    frame.pack();
    frame.setVisible(true);
  }
 @Override
 public void onPointerMoved(TelepointerEvent e) {
   client.movePointer(e.getPoint());
   frame.repaint();
 }