Example #1
1
  // --------------------------------actionConnect------------------------------
  private void actionConnect() {
    if (oParty == null) {
      JOptionPane.showMessageDialog(frame, "Make a party before trying to connect.");
      return;
    }

    String[] oResults = (String[]) DialogManager.show(DialogManager.CONNECT, frame);

    if (oResults[DialogManager.RETURN_IP].equals("cancel")) return;

    lblStatus3.setText("Connecting...");
    try {
      oConn.connect(
          oResults[DialogManager.RETURN_IP], Integer.parseInt(oResults[DialogManager.RETURN_PORT]));
    } catch (UnknownHostException e) {
      JOptionPane.showMessageDialog(
          frame,
          "The IP of the host cannot be determined.",
          "Unknown Host Exception",
          JOptionPane.ERROR_MESSAGE);
      frame.repaint();
      return;
    } catch (IOException e) {
      JOptionPane.showMessageDialog(
          frame, e.getMessage(), "Input/Output Exception", JOptionPane.ERROR_MESSAGE);
      frame.repaint();
      return;
    }
    echo("Connected to opponent!");

    tConn = new Thread(oConn, "conn");
    tConn.start();
    tMain = new Thread(this, "main");
    tMain.start();
  }
Example #2
1
  // --------------------------------actionHost---------------------------------
  private void actionHost() {
    if (oParty == null) {
      JOptionPane.showMessageDialog(frame, "Make a party before trying to connect.");
      return;
    }

    JFileChooser oFC = new JFileChooser(DEFAULT_MAP_DIRECTORY);
    int nReturn = oFC.showOpenDialog(frame);

    if (nReturn == JFileChooser.CANCEL_OPTION) {
      return;
    }

    int nPort = Integer.parseInt((String) (DialogManager.show(DialogManager.HOST, frame)));

    JDialog dlgBox = (JDialog) (DialogManager.show(DialogManager.WAITING_FOR_CONN, frame));
    dlgBox.pack();
    try {
      oConn.host(nPort);
    } catch (IOException e) {
      JOptionPane.showMessageDialog(frame, e.getMessage(), "Error!", JOptionPane.ERROR_MESSAGE);
      frame.repaint();
      return;
    }
    dlgBox.setVisible(false);
    echo("Connected to opponent!");

    tConn = new Thread(oConn, "conn");
    tConn.start();
    tMain = new Thread(this, "main");
    tMain.start();

    try {
      oMap.loadMap(oFC.getSelectedFile());
      oConn.send("loadmap", oFC.getName(oFC.getSelectedFile()));
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(-1);
    }
  }