コード例 #1
0
 public void submit() {
   dbTextArea.clear();
   LocalDate from = fromDate.getValue(), to = toDate.getValue();
   Future<String[]> fwarNames = db.getWarNamesByDate(from, to);
   HashSet<Future<long[]>> fstats = new HashSet<Future<long[]>>();
   try {
     String[] warNames = fwarNames.get();
     for (String war : warNames) {
       fstats.add(db.getWarStats(war));
     }
     int i = 0;
     for (Future<long[]> fWarStats : fstats) {
       long[] stats = fWarStats.get();
       dbTextArea.appendText("\t" + warNames[i++] + " Statistics\n");
       dbTextArea.appendText("=========================================\n");
       dbTextArea.appendText('\t' + stats[0] == 0 ? "War is still running" : "\tWar has ended\n");
       dbTextArea.appendText("\tNum of launch missiles: " + stats[1] + "\n");
       dbTextArea.appendText("\tNum of intercept missiles: " + stats[2] + "\n");
       dbTextArea.appendText("\tNum of hit target missiles: " + stats[3] + "\n");
       dbTextArea.appendText("\tNum of launchers destroyed: " + stats[4] + "\n");
       dbTextArea.appendText("\ttotal damage: " + stats[5] + "\n");
       dbTextArea.appendText("==========================================\n");
     }
   } catch (InterruptedException | ExecutionException e) {
     e.printStackTrace();
   }
 }
コード例 #2
0
ファイル: FFOTesterViewer.java プロジェクト: syanidar/KI-84
 FFOTesterViewer(FFOTesterController controller, Board board) {
   this.controller = controller;
   this.board = board;
   this.com = new PVS(this, PatternRecognitioner.INSTANCE, 1, 40, 1000000000);
   TextArea log = controller.log;
   valueProperty()
       .addListener(
           (observable, oldValue, newValue) -> {
             log.appendText(com.toString());
             log.appendText(System.lineSeparator());
             log.appendText(newValue.toString());
             log.appendText(System.lineSeparator());
             completedUpdate = true;
           });
 }
コード例 #3
0
ファイル: ServerFX.java プロジェクト: g00291875/FYP-Server
 // Shows the messages // Updates chatwindow
 private static void showMessage(final String text) {
   // Creating a thread
   Platform.runLater(
       () -> {
         // Adds a message to the end of document. Updating the Chat Window.
         chatWindow.appendText(text);
       });
 }
コード例 #4
0
ファイル: ServerFX.java プロジェクト: g00291875/FYP-Server
 // Send message to client
 private static void sendMessage(String message) {
   try { // Sends a message through the output. Create an object and send to your outputstream
     output.writeObject("SERVER - " + message);
     // In case you have any bytes leftover, we flush it for safety and clear the buffer
     output.flush();
     showMessage("\nSERVER - " + message);
   } catch (IOException e) {
     chatWindow.appendText("\n ERROR: Can't send that message. Try again...");
   }
 }
コード例 #5
0
ファイル: Main.java プロジェクト: markalexis/FinanceModel
 //
 // Action When "Run" is pressed,
 //
 @Override
 public void handle(ActionEvent e) {
   // String currentText = textStatus.getText();
   // textStatus.setText(currentText + ", Run button pressed, more text wider than normal to
   // see if the text box will wrap>>>");
   YearData[] yd = MU.runMultiYearModel(30);
   for (int i = 0; i < yd.length; i++) {
     // Print out a result
     String msg = yd[i].toString();
     textStatus.appendText(msg + "\n");
   }
   tableV.setItems(MU.modelDataList);
 }
コード例 #6
0
 public void appendToProtocol(String string) {
   textArea.appendText(string);
   textArea.appendText("\n");
 }
コード例 #7
0
ファイル: ChatServer.java プロジェクト: setlink/Testing
 /*
 public static void main(String[] args) {
 launch(args);
 }
 */
 private void printString(String str) {
   Platform.runLater(
       () -> {
         ta.appendText(str + "\n");
       });
 }
コード例 #8
0
  private void render() {
    ArrayList<NetworkMessage> messages = networkController.getMessages();

    for (NetworkMessage message : messages) {
      String messageType =
          message.getClass().getName().replace("NetworkMessages.", "").replace("Messages.", "");
      switch (messageType) {
        case "PelletPositionMessage":
          {
            PelletPositionMessage m = (PelletPositionMessage) message;
            Drawable drawable = getCachedDrawable(m.id);
            if (drawable != null) {
              drawable.node.relocate(m.x, m.y);
              drawable.cacheMisses = 0;
            } else {
              Random r = new Random();
              Node node =
                  drawCircle(
                      m.x, m.y, 5, new Color(r.nextFloat(), r.nextFloat(), r.nextFloat(), 1));
              drawableCache.add(new Drawable(m.id, node));
            }
          }
          break;
        case "BlobStateMessage":
          {
            BlobStateMessage m = (BlobStateMessage) message;
            Color color = Color.web(m.color);
            Node node;
            if (color.getBrightness() != 0) {
              node = drawCircle(m.x, m.y, m.size / 2, color);
            } else {
              node = drawCircle(m.x, m.y, m.size / 2, color.brighter().brighter());
            }
            Node nameText =
                drawText((m.x - m.username.length() * 5), (m.y - m.size / 2), m.username, color);
            Drawable drawable = getCachedDrawable(m.id);
            if (drawable != null) {
              node.setLayoutX((drawable.node.getTranslateX() - m.x) / 10000);
              node.setLayoutY((drawable.node.getTranslateY() - m.y) / 10000);
              drawable.node = node;
              drawable.cacheMisses = 0;
              Drawable nameTag = getCachedDrawable(m.id + 9000);
              nameTag.node = nameText;
              nameTag.cacheMisses = 0;
            } else {
              drawableCache.add(new Drawable(m.id, node));
              drawableCache.add(new Drawable(m.id + 9000, nameText));
            }
          }
          break;
        case "PingMessage":
          {
            renderPane.getChildren().clear();
            ArrayList<Drawable> drawables = new ArrayList<>(drawableCache);
            for (Drawable drawable : drawables) {
              if (drawable.cacheMisses > 1) {
                drawableCache.remove(drawable);
              }
              drawable.cacheMisses++;
              renderPane.getChildren().add(drawable.node);
            }
            renderPane.getChildren().addAll(chatBox, chatInput, lagLabel, scores);

            lag = System.currentTimeMillis() - lastReceivedTime;
            lastReceivedTime = System.currentTimeMillis();
            lagLabel.setText("Net Lag: " + Long.toString(lag));
          }
          break;
        case "HighScoreMessage":
          {
            HighScoreMessage m = (HighScoreMessage) message;
            highScores.setText("HIGH SCORES:" + m.text);
          }
          break;
        case "CurrentScoreMessage":
          {
            CurrentScoreMessage m = (CurrentScoreMessage) message;
            currentScores.setText("Current Scores:" + m.text);
          }
          break;
        case "ChatMessage":
          {
            ChatMessage m = (ChatMessage) message;
            chatBox.appendText(m.username + "> " + m.text + "\n");
          }
          break;
      }
    }
  }
コード例 #9
0
  @Override
  public void doMove(
      String s,
      Table table,
      WhitePlayer whitePlayer,
      BlackPlayer blackPlayer,
      ArrayList<SaveState> saveStateArrayList,
      SaveState previousState,
      TextArea status)
      throws IOException, Mate, CheckIsOpen, CastlingDone, ChangePawn {

    // BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
    while (!s.equals("exit")) {
      saveStateArrayList.add(new SaveState(table, whitePlayer, blackPlayer));
      previousState = saveStateArrayList.get(saveStateArrayList.size() - 1);
      boolean nextToBlack = false;

      System.out.println("White player moves: " + s);
      // s = reader.readLine();

      try {

        new WhiteMove(s).move(table, whitePlayer, blackPlayer);

        Cell myKingCell =
            table.getOpponentKingCell(
                WHITE, whitePlayer.getChessItemsMap(), blackPlayer.getChessItemsMap(), table);

        // is Check to my king?
        if (Move.isInAllItemsOfAvailableCellListBlack(
            myKingCell, blackPlayer.getChessItemsMap(), table)) {
          System.out.println("Black player will Announce you Check and Mate");
          // Undo Last Move
          previousState.undoHere(table, whitePlayer, blackPlayer);
          // Undo Last Move
          table.toString();
          throw new CheckIsOpen();
        }
        // table.toString();
        nextToBlack = true;
      } catch (PlayerSameChessItem playerSameChessItem) {
        System.out.println("Source & Target are the same");

      } catch (EmptySourceCell emptySourceCell) {
        System.out.println("Source Cell is empty");

      } catch (InvalidSource invalidSource) {
        System.out.println("Source is invalid");
      } catch (NoCell noCell) {

      } catch (InvalidMoveString invalidMoveString) {
        System.out.println("String is invalid");

      } catch (InvalidMove invalidMove) {

      } catch (NoAvailableCells noAvailableCells) {
        System.out.println("No Available Cells");
      } /*catch (Check check) {

        }*/
      if (nextToBlack) {
        // is Check or not?
        Cell kingCell =
            table.getOpponentKingCell(
                BLACK, whitePlayer.getChessItemsMap(), blackPlayer.getChessItemsMap(), table);
        if (Move.isInAllItemsOfAvailableCellListWhite(
            kingCell, whitePlayer.getChessItemsMap(), table)) {
          try {
            throw new Check();
          } catch (Check check) {
            System.out.println("Check to Black Army");
            // is Mate or not?
            ArrayList<BlackTestMove> blackTestMoves = new ArrayList<>();
            saveStateArrayList.add(new SaveState(table, whitePlayer, blackPlayer));
            previousState = saveStateArrayList.get(saveStateArrayList.size() - 1);

            for (SortedMap.Entry<String, ChessItem> item :
                blackPlayer.getChessItemsMap().entrySet()) {
              if (item.getValue() instanceof BlackKing) {
                try {
                  for (Cell cell :
                      new BlackKingMoves(table.getCellByString(item.getKey()), table, true)
                          .getMoves()) {
                    blackTestMoves.add(
                        new BlackTestMove(
                            item.getValue().toString(), item.getKey(), cell.toString()));
                  }
                } catch (NoAvailableCells noAvailableCells) {

                }
              }
              if (item.getValue() instanceof BlackQueen) {
                try {
                  for (Cell cell :
                      new BlackQueenMoves(table.getCellByString(item.getKey()), table).getMoves()) {
                    blackTestMoves.add(
                        new BlackTestMove(
                            item.getValue().toString(), item.getKey(), cell.toString()));
                  }
                } catch (NoAvailableCells noAvailableCells) {

                }
              }
              if (item.getValue() instanceof BlackBishop) {
                try {
                  for (Cell cell :
                      new BlackBishopMoves(table.getCellByString(item.getKey()), table)
                          .getMoves()) {
                    blackTestMoves.add(
                        new BlackTestMove(
                            item.getValue().toString(), item.getKey(), cell.toString()));
                  }
                } catch (NoAvailableCells noAvailableCells) {

                }
              }
              if (item.getValue() instanceof BlackKnight) {
                try {
                  for (Cell cell :
                      new BlackKnightMoves(table.getCellByString(item.getKey()), table)
                          .getMoves()) {
                    blackTestMoves.add(
                        new BlackTestMove(
                            item.getValue().toString(), item.getKey(), cell.toString()));
                  }
                } catch (NoAvailableCells noAvailableCells) {

                }
              }
              if (item.getValue() instanceof BlackPawn) {
                try {
                  for (Cell cell :
                      new BlackPawnMoves(table.getCellByString(item.getKey()), table).getMoves()) {
                    blackTestMoves.add(
                        new BlackTestMove(
                            item.getValue().toString(), item.getKey(), cell.toString()));
                  }
                } catch (NoAvailableCells noAvailableCells) {

                }
              }
              if (item.getValue() instanceof BlackRook) {
                try {
                  for (Cell cell :
                      new BlackRookMoves(table.getCellByString(item.getKey()), table).getMoves()) {
                    blackTestMoves.add(
                        new BlackTestMove(
                            item.getValue().toString(), item.getKey(), cell.toString()));
                  }
                } catch (NoAvailableCells noAvailableCells) {

                }
              }
            }

            ArrayList<BlackTestMove> availableMoves = new ArrayList<>();
            try {

              if (blackTestMoves.size() > 0) {
                for (BlackTestMove move : blackTestMoves) {
                  if (move.getChessItem().equals(Black.KING)) {
                    new BlackMove(move.getSource(), move.getDestination())
                        .move(table, whitePlayer, blackPlayer);

                    if (!(Move.isInAllItemsOfAvailableCellListWhite(
                        table.getCellByString(move.getDestination()),
                        whitePlayer.getChessItemsMap(),
                        table))) {
                      availableMoves.add(move);
                    }
                    previousState.undoHere(table, whitePlayer, blackPlayer);
                  } else {
                    new BlackMove(move.getSource(), move.getDestination())
                        .move(table, whitePlayer, blackPlayer);

                    if (!(Move.isInAllItemsOfAvailableCellListWhite(
                        kingCell, whitePlayer.getChessItemsMap(), table))) {
                      availableMoves.add(move);
                    }
                    previousState.undoHere(table, whitePlayer, blackPlayer);
                  }
                }
                if (availableMoves.size() == 0) {
                  throw new Mate(BLACK);
                } else {
                  status.appendText("Available moves for black player are:\n");
                  System.out.println("Available moves for black player are:");
                  for (BlackTestMove move : availableMoves) {
                    status.appendText(move.toString() + "\n");
                    System.out.println(move.toString());
                  }
                }
              }
            } catch (NoAvailableCells noAvailableCells) {

            } catch (NoCell noCell) {

            } catch (InvalidMove invalidMove) {

            } catch (PlayerSameChessItem playerSameChessItem) {

            } catch (EmptySourceCell emptySourceCell) {

            } catch (InvalidSource invalidSource) {

            }
          }
        }
        saveState = new SaveState(table, whitePlayer, blackPlayer);
        table.toString();
        break;
      }
    }
  }
コード例 #10
0
ファイル: ChatWindow.java プロジェクト: mritter-tgm/JMSChat
  @Override
  public void print(String text) {

    showMessages.appendText(text + "\n");
  }
コード例 #11
0
 private void printMessageToChat(String username, String message) {
   outputField.appendText(username + ":" + message + "\n");
 }