Exemple #1
0
 public int showOptionDialog(
     Object message,
     String title,
     int optionType,
     int messageType,
     Icon icon,
     Object[] options,
     Object initialValue) {
   return JOptionPane.showOptionDialog(
       this.getFrame(), message, title, optionType, messageType, icon, options, initialValue);
 }
Exemple #2
0
 protected boolean informUserError(String msg) // this is just for SPPmon
     {
   if (!ExpCoordinator.isSPPMon()) return false;
   final String opt0 = "Try Again";
   final String opt1 = "Cancel";
   JLabel lbl = new JLabel(msg);
   TextFieldwLabel tfaddress = new TextFieldwLabel(30, "daemon addr:");
   tfaddress.setText(host);
   TextFieldwLabel tfport = new TextFieldwLabel(30, "daemon port:");
   tfport.setText(String.valueOf(port));
   Object[] params = {lbl, tfaddress, tfport};
   Object[] options = {opt0, opt1};
   int rtn =
       JOptionPane.showOptionDialog(
           ExpCoordinator.getMainWindow(),
           params,
           "Connection Error",
           JOptionPane.YES_NO_OPTION,
           JOptionPane.WARNING_MESSAGE,
           null,
           options,
           options[0]);
   if (rtn == JOptionPane.NO_OPTION) {
     connectionFailed();
     return false;
   } else {
     String tmp_host = host;
     boolean change = false;
     if (tfaddress.getText().length() > 0) tmp_host = tfaddress.getText();
     int tmp_port = port;
     if (tfport.getText().length() > 0) tmp_port = Integer.parseInt(tfport.getText());
     if (!tmp_host.equals(host)) {
       host = new String(tmp_host);
       change = true;
     }
     if (port != tmp_port) {
       port = tmp_port;
       change = true;
     }
     if (change) fireEvent(new ConnectionEvent(this, ConnectionEvent.ADDRESS_CHANGED));
     state = ConnectionEvent.CONNECTION_CLOSED;
     return (connect());
   }
 }
Exemple #3
0
  public JavaGame(String[] args) {
    this.args = args;
    updater = new Updater(this);
    highscore = new Highscore(this);
    eventHandler = new EventHandler(this);
    eventHandler.registerTestEvents();

    setTitle("Survive-JavaGame"); // Fenstertitel setzen
    setSize(1200, 900); // Fenstergröße einstellen
    addWindowListener(new WindowListener());
    setLocationRelativeTo(null);

    try {
      arg = args[0];
    } catch (ArrayIndexOutOfBoundsException e) {
      arg = "nothing";
    }
    if (arg.equals("fullscreen")) {
      setUndecorated(true); // "Vollbild"
      setSize(
          (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth() - 200,
          (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth());
      setLocation(0, 0);
    }
    setVisible(true);
    setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));

    try {
      /*URI Path = URLDecoder.decode(getClass().getClassLoader().getResource("texture").toURI();//, "UTF-8"); //Pfad zu den Resourcen
      File F = new File(Path);
      basePath = F;
      System.out.println(basePath);
      */
      File File = new File((System.getenv("APPDATA")));
      basePath = new File(File, "/texture");
      backgroundTexture = new File(basePath, "/hintergrund.jpg");
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    try {
      backgroundImage = ImageIO.read(backgroundTexture);
    } catch (IOException exeption) {

    }

    if (soundan) {
      currentVolume = 80;
    } // end of if

    dbImage = createImage(1920, 1080);
    // dbGraphics = dbImage.getGraphics();

    // Texturen Liste

    // Ebenen Liste

    ebenen[0][0] = 91;
    ebenen[0][1] = 991; // Main Ebene: Kann nicht durchschrittenwerden indem down gedrückt wird
    ebenen[0][2] = 563;

    ebenen[1][0] = 387; // x1
    ebenen[1][1] = 524; // x2
    ebenen[1][2] = 454; // y

    ebenen[2][0] = 525;
    ebenen[2][1] = 645;
    ebenen[2][2] = 350;

    ebenen[3][0] = 246;
    ebenen[3][1] = 365;
    ebenen[3][2] = 351;

    ebenen[4][0] = 760;
    ebenen[4][1] = 870;
    ebenen[4][2] = 294;

    ebenen[5][0] = 835;
    ebenen[5][1] = 969;
    ebenen[5][2] = 441;

    // Spieler

    // I'm in Space! SPACE!
    player[1] =
        new Player(
            (int) (Math.random() * (ebenen[0][1] - ebenen[0][0]) + ebenen[0][0]),
            0,
            false,
            67,
            100,
            texture[0],
            shottexture[0],
            KeyEvent.VK_A,
            KeyEvent.VK_D,
            KeyEvent.VK_W,
            KeyEvent.VK_S,
            KeyEvent.VK_Q,
            1,
            35,
            highscore.getName(1));
    player[2] =
        new Bot(
            (int) (Math.random() * (ebenen[0][1] - ebenen[0][0]) + ebenen[0][0]),
            0,
            false,
            67,
            100,
            texture[1],
            shottexture[1],
            KeyEvent.VK_J,
            KeyEvent.VK_L,
            KeyEvent.VK_I,
            KeyEvent.VK_K,
            KeyEvent.VK_U,
            2,
            35,
            highscore.getName(1));
    player[3] =
        new Bot(
            (int) (Math.random() * (ebenen[0][1] - ebenen[0][0]) + ebenen[0][0]),
            0,
            false,
            67,
            100,
            texture[2],
            shottexture[2],
            KeyEvent.VK_LEFT,
            KeyEvent.VK_RIGHT,
            KeyEvent.VK_UP,
            KeyEvent.VK_DOWN,
            KeyEvent.VK_ENTER,
            3,
            35,
            highscore.getName(1));

    player[1].laden(this);
    player[2].laden(this);
    player[3].laden(this);

    this.addKeyListener(player[1]);
    this.addKeyListener(player[2]);
    this.addKeyListener(player[3]);

    this.addKeyListener(this);

    int result;
    Object[] options = {"SinglePlayer", "MultiPlayer"};
    if (arg.equals("dedicated")) {
      Server server = new Server();
      this.server = true;
      setVisible(false);

    } else {
      if ((result =
              JOptionPane.showOptionDialog(
                  null,
                  "Treffen Sie eine Auswahl",
                  "Alternativen",
                  JOptionPane.DEFAULT_OPTION,
                  JOptionPane.INFORMATION_MESSAGE,
                  null,
                  options,
                  options[0]))
          == 1) {
        client = new Client(this);
        online = true;
        while ((onlinename =
                    JOptionPane.showInputDialog(
                        null,
                        "Geben Sie Ihren Namen ein",
                        "Eine Eingabeaufforderung",
                        JOptionPane.PLAIN_MESSAGE))
                .isEmpty()
            && onlinename != null) {}

        Object[] optionsmp = {"Host", "Client"};
        if ((result =
                JOptionPane.showOptionDialog(
                    null,
                    "Treffen Sie eine Auswahl",
                    "Alternativen",
                    JOptionPane.DEFAULT_OPTION,
                    JOptionPane.INFORMATION_MESSAGE,
                    null,
                    optionsmp,
                    optionsmp[0]))
            == 0) {
          Server server = new Server();
          this.server = true;
        } else if (online) {
          while ((serveradresse =
                      JOptionPane.showInputDialog(
                          null,
                          "Geben Sie die Serveradresse ein",
                          "Eine Eingabeaufforderung",
                          JOptionPane.PLAIN_MESSAGE))
                  .isEmpty()
              && serveradresse != null) {}
        }
      }
    }
    if (!arg.equals("dedicated")) {
      gamerunner = new GameRunner(player, this);
      DamageLogig = new damageLogig(gamerunner);
    }

    if (online) {
      try {
        client.initialise(serveradresse, 9876);
        client.start();
      } catch (SocketException e) {
        e.printStackTrace();
      } catch (UnknownHostException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  } // end of init
  public void realize(XMLTree xtXMLTree) {
    try {
      TreeComponent tcSiteTreeComponent;
      TreeComponent tcSiteTreeComponentParent;
      TreeComponent tcXMLTopTreeComponent;
      TreeVisit tvTreeVisit;
      TreeVisitToFindTreeComponent tvftcTreeVisitToFindTreeComponent;
      TreeComponent tcSiteToRemoveTreeComponent;

      tcSiteTreeComponent = xtXMLTree.getSelectedTreeComponent();

      if (tcSiteTreeComponent.getChildCount() != 0) {
        JOptionPane.showMessageDialog(
            null, "The site is not empty", "DeleteSite", JOptionPane.ERROR_MESSAGE);

        return;
      }

      if (JOptionPane.showOptionDialog(
              null,
              "Are you sure?",
              "DeleteSite",
              JOptionPane.YES_NO_OPTION,
              JOptionPane.QUESTION_MESSAGE,
              null,
              null,
              null)
          == 1) return;

      if (ConfigurationTransaction.beginGUIConfigurationTransaction(
              _xtfcXMLTreeForConfiguration.getXML().getFile(), _pProperties.getProperty("login"))
          != 0) {
        JOptionPane.showMessageDialog(
            null,
            "beginGUIConfigurationTransaction failed",
            "DeleteSite",
            JOptionPane.ERROR_MESSAGE);

        return;
      }

      tcSiteTreeComponentParent = (TreeComponent) tcSiteTreeComponent.getParent();

      xtXMLTree.setSelectedTreeComponent(tcSiteTreeComponentParent);
      tcSiteTreeComponentParent.remove(tcSiteTreeComponent);
      tcSiteTreeComponentParent.refreshSubTree();

      // XMLTreeForContents
      tcXMLTopTreeComponent = _xtfcXMLTreeForContents.getXMLTopTreeComponent();
      tvftcTreeVisitToFindTreeComponent =
          new TreeVisitToFindTreeComponent(
              "Site", tcSiteTreeComponent.getAttributeValue("Identifier"));
      tvTreeVisit = new TreeVisit(tvftcTreeVisitToFindTreeComponent);

      if (tvTreeVisit.preOrderVisit(tcXMLTopTreeComponent) != 0) {
        JOptionPane.showMessageDialog(
            null, "preOrderVisit failed", "DeleteSite", JOptionPane.ERROR_MESSAGE);

        if (ConfigurationTransaction.rollbackGUIConfigurationTransaction(
                _xtfcXMLTreeForConfiguration.getXML().getFile())
            != 0) {
          JOptionPane.showMessageDialog(
              null,
              "rollbackGUIConfigurationTransaction failed",
              "DeleteSite",
              JOptionPane.ERROR_MESSAGE);
        }

        return;
      }

      if ((tcSiteToRemoveTreeComponent = tvftcTreeVisitToFindTreeComponent.getTreeComponentFound())
          == null) {
        JOptionPane.showMessageDialog(
            null,
            "TreeComponent not found (TagName: Site, Identifier: "
                + tcSiteTreeComponent.getAttributeValue("Identifier")
                + ")",
            "DeleteSite",
            JOptionPane.ERROR_MESSAGE);

        if (ConfigurationTransaction.rollbackGUIConfigurationTransaction(
                _xtfcXMLTreeForConfiguration.getXML().getFile())
            != 0) {
          JOptionPane.showMessageDialog(
              null,
              "rollbackGUIConfigurationTransaction failed",
              "DeleteSite",
              JOptionPane.ERROR_MESSAGE);
        }

        return;
      }
      tcXMLTopTreeComponent.remove(tcSiteToRemoveTreeComponent);
      tcXMLTopTreeComponent.refreshSubTree();

      // XMLTreeForMonitor
      tcXMLTopTreeComponent = _xtfmXMLTreeForMonitor.getXMLTopTreeComponent();
      tvftcTreeVisitToFindTreeComponent =
          new TreeVisitToFindTreeComponent(
              "Site", tcSiteTreeComponent.getAttributeValue("Identifier"));
      tvTreeVisit = new TreeVisit(tvftcTreeVisitToFindTreeComponent);

      if (tvTreeVisit.preOrderVisit(tcXMLTopTreeComponent) != 0) {
        JOptionPane.showMessageDialog(
            null, "preOrderVisit failed", "DeleteSite", JOptionPane.ERROR_MESSAGE);

        if (ConfigurationTransaction.rollbackGUIConfigurationTransaction(
                _xtfcXMLTreeForConfiguration.getXML().getFile())
            != 0) {
          JOptionPane.showMessageDialog(
              null,
              "rollbackGUIConfigurationTransaction failed",
              "DeleteSite",
              JOptionPane.ERROR_MESSAGE);
        }

        return;
      }

      if ((tcSiteToRemoveTreeComponent = tvftcTreeVisitToFindTreeComponent.getTreeComponentFound())
          == null) {
        JOptionPane.showMessageDialog(
            null,
            "TreeComponent not found (TagName: Site, Identifier: "
                + tcSiteTreeComponent.getAttributeValue("Identifier")
                + ")",
            "DeleteSite",
            JOptionPane.ERROR_MESSAGE);

        if (ConfigurationTransaction.rollbackGUIConfigurationTransaction(
                _xtfcXMLTreeForConfiguration.getXML().getFile())
            != 0) {
          JOptionPane.showMessageDialog(
              null,
              "rollbackGUIConfigurationTransaction failed",
              "DeleteSite",
              JOptionPane.ERROR_MESSAGE);
        }

        return;
      }
      tcXMLTopTreeComponent.remove(tcSiteToRemoveTreeComponent);
      tcXMLTopTreeComponent.refreshSubTree();

      if (ConfigurationTransaction.commitGUIConfigurationTransaction(
              _xtfcXMLTreeForConfiguration, _xtfcXMLTreeForConfiguration.getFunctionalities())
          != 0) {
        JOptionPane.showMessageDialog(
            null,
            "commitGUIConfigurationTransaction failed",
            "DeleteSite",
            JOptionPane.ERROR_MESSAGE);

        return;
      }
    } catch (Exception e) {
      JOptionPane.showMessageDialog(
          null, "DeleteSite ERROR: " + e, "DeleteSite", JOptionPane.ERROR_MESSAGE);

      if (ConfigurationTransaction.rollbackGUIConfigurationTransaction(
              _xtfcXMLTreeForConfiguration.getXML().getFile())
          != 0) {
        JOptionPane.showMessageDialog(
            null,
            "rollbackGUIConfigurationTransaction failed",
            "DeleteSite",
            JOptionPane.ERROR_MESSAGE);
      }

      return;
    }
  }