Ejemplo n.º 1
1
    @Override
    public void run() {
      while (true) {
        if (istWindows()) aktuell = holeLaufwerkeWindows();
        else aktuell = holeLaufwerkeUnix();

        if (initial.size() != aktuell.size()) {
          if (!initial.containsAll(aktuell)) {
            neuesLaufwerk = holePathVonNeuemLaufwerk(initial, aktuell);
            textArea.append("Neues Laufwerk endeckt:  " + neuesLaufwerk + System.lineSeparator());
            this.initial = (ArrayList<Path>) aktuell.clone();
            neuesLaufwerkDialog();

          } else {
            this.initial = (ArrayList<Path>) aktuell.clone();
            textArea.append("Laufwerk wurde entfernt" + System.lineSeparator());
          }
        }

        try {
          Thread.sleep(5000);
        } catch (InterruptedException e) {
          System.out.println("Laufwerksprüfung wird abgebrochen");
        }
      }
    }
Ejemplo n.º 2
1
  @Override
  public void run() {
    // TODO Auto-generated method stub
    while (true) {
      try {
        Thread.sleep(100);
      } catch (Exception e) {
        // TODO: handle exception
      }
      //			判断每一粒子弹和每一辆敌人的坦克都是否有重合(击中)
      for (int i = 0; i < hero.bombs.size(); i++) {
        //				取出每个子弹
        Bomb myBomb = hero.bombs.get(i);
        //				子弹必须得存活才有判断的意义
        if (myBomb.isLive) {
          for (int j = 0; j < ets.size(); j++) {
            //						取出每辆坦克
            EnemyTank et = ets.get(j);
            if (et.isLive) {
              this.isHit(myBomb, et);
            }
          }
        }
      }

      this.repaint();
    }
  }
Ejemplo n.º 3
0
    public void run() {
      while (_connected) {
        try {
          Thread.sleep(25);
          if (_specialRequest != null) {
            for (final char c : _specialRequest.toCharArray()) {
              final StringBuffer buf = new StringBuffer();
              buf.append(c);
              sendMessage(buf.toString());
              Thread.sleep(2000);
            }
            _specialRequest = null;

          } else if (_transmitterValue != null) {
            _lastRequest =
                _lastRequest.equals(FLIGHT_DATA_REQUEST)
                    ? SENSORS_DATA_REQUEST
                    : FLIGHT_DATA_REQUEST;
            _transmitterValue += _lastRequest;
            sendMessage(_transmitterValue);
            _transmitterValue = null;
          }

        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
Ejemplo n.º 4
0
  protected void flushSerialBuffer() throws RunnerException, SerialException {
    // Cleanup the serial buffer
    try {
      Serial serialPort = new Serial();
      byte[] readBuffer;
      while (serialPort.available() > 0) {
        readBuffer = serialPort.readBytes();
        try {
          Thread.sleep(100);
        } catch (InterruptedException e) {
        }
      }

      serialPort.setDTR(false);
      serialPort.setRTS(false);

      try {
        Thread.sleep(100);
      } catch (InterruptedException e) {
      }

      serialPort.setDTR(true);
      serialPort.setRTS(true);

      serialPort.dispose();
    } catch (SerialNotFoundException e) {
      throw e;
    } catch (Exception e) {
      e.printStackTrace();
      throw new RunnerException(e.getMessage());
    }
  }
    public synchronized void run() {
      while (!m_quit) {
        // System.out.println("Sending statuspoller W!! ");
        try {
          if (m_cryoPanel != null && !m_paused) {
            if (initialDelay > 0) {
              Thread.sleep(initialDelay);
              initialDelay = 0;
            }
            if (dataCount == 0) {
              dataCount++;
              sendCommand(CMD_CLOCK);
              sendCommand(CMD_PARAMS);
            } else {
              dataCount++;
              sendCommand(CMD_CLOCK);
            }
            if (dataCount == dataUpdate) dataCount = 0;

            Thread.sleep(m_rate_ms);
          }
        } catch (InterruptedException ie) {
        }
      }
    }
Ejemplo n.º 6
0
  private static BibEntry downloadEntryBibTeX(String id, boolean downloadAbstract) {
    try {
      URL url =
          new URL(
              ACMPortalFetcher.START_URL
                  + ACMPortalFetcher.BIBTEX_URL
                  + id
                  + ACMPortalFetcher.BIBTEX_URL_END);
      URLConnection connection = url.openConnection();

      // set user-agent to avoid being blocked as a crawler
      connection.addRequestProperty(
          "User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0");
      Collection<BibEntry> items = null;
      try (BufferedReader in =
          new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
        items = BibtexParser.parse(in).getDatabase().getEntries();
      } catch (IOException e) {
        LOGGER.info("Download of BibTeX information from ACM Portal failed.", e);
      }
      if ((items == null) || items.isEmpty()) {
        return null;
      }
      BibEntry entry = items.iterator().next();
      Thread.sleep(
          ACMPortalFetcher.WAIT_TIME); // wait between requests or you will be blocked by ACM

      // get abstract
      if (downloadAbstract) {
        url = new URL(ACMPortalFetcher.START_URL + ACMPortalFetcher.ABSTRACT_URL + id);
        String page = Util.getResults(url);
        Matcher absM = ACMPortalFetcher.ABSTRACT_PATTERN.matcher(page);
        if (absM.find()) {
          entry.setField("abstract", absM.group(1).trim());
        }
        Thread.sleep(
            ACMPortalFetcher.WAIT_TIME); // wait between requests or you will be blocked by ACM
      }

      return entry;
    } catch (NoSuchElementException e) {
      LOGGER.info(
          "Bad BibTeX record read at: "
              + ACMPortalFetcher.BIBTEX_URL
              + id
              + ACMPortalFetcher.BIBTEX_URL_END,
          e);
      return null;
    } catch (MalformedURLException e) {
      LOGGER.info("Malformed URL.", e);
      return null;
    } catch (IOException e) {
      LOGGER.info("Cannot connect.", e);
      return null;
    } catch (InterruptedException ignored) {
      return null;
    }
  }
Ejemplo n.º 7
0
 static void blinkMenu(final Selectable selectable) {
   if (!animationsEnabled()) return;
   try {
     selectable.paintSelected(false);
     Thread.sleep(MENU_BLINK_DELAY);
     selectable.paintSelected(true);
     Thread.sleep(MENU_BLINK_DELAY);
   } catch (final InterruptedException ignored) {
   }
 }
Ejemplo n.º 8
0
  public void appear(final CardGui card) {
    moving = card;
    player1.animations.add(moving);
    Thread t =
        new Thread(
            () -> {
              moving.setBounds(925 - 62, 609 - 93, 0, 0);
              int i = 0, j = 0;
              while (i <= 124 || j <= 186) {
                try {
                  if (i <= 124) {
                    i++;
                    moving.setBounds(925 - 62, 609 - 93, i, j);
                    Thread.sleep(1);
                  }
                  if (j <= 186) {
                    j++;
                    moving.setBounds(925 - 62, 609 - 93, i, j);

                    Thread.sleep(1);
                  }
                } catch (InterruptedException e) {
                  e.printStackTrace();
                }
              }
              i = 925 - 62;

              while (i >= 652) {
                i--;
                try {
                  Thread.sleep(1);
                } catch (InterruptedException e) {
                  e.printStackTrace();
                }
                moving.setLocation(i, 609 - 93);
              }

              player1.animations.remove(moving);
              player1.repairListeners(false);
              PlayGui.player.pdeck.textField.setText(
                  "cards left " + PlayGui.player.pdeck.Deck.cardsLeft());
              player1.cardDrawn = 1;
              PlayGui.player.pdeck.textField.repaint();
              setVisible(true);
              repaint();
            });
    t.start();
  }
Ejemplo n.º 9
0
  public String set_old_key(String keyx) {

    System.out.println("Build old keys");

    while (network.database_in_use == 1) {

      int test_db = 0;
      System.out.println("Database in use... import key");
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
      }
      test_db++;
    } // *********************************

    mining.mining3 = false;

    krypton_database_import_keys import_kx = new krypton_database_import_keys(keyx);

    krypton_database_load_network xxn = new krypton_database_load_network();
    krypton_database_load xxs = new krypton_database_load();

    mining.mining3 = true;

    return network.settingsx[5];
  } // **********************
Ejemplo n.º 10
0
  private void tryToInitialize(int counter) {
    boolean existsCompatibleBrowser = getComponent() != null && isCompatible();
    synchronized (this) {
      initialized = existsCompatibleBrowser;
    }
    log.info(System.currentTimeMillis() + " initialized map: " + initialized);

    if (isInitialized()) {
      log.fine(System.currentTimeMillis() + " compatible, further initializing map");
      initializeAfterLoading();
      initializeBrowserInteraction();
      initializeCallbackListener();
      checkLocalhostResolution();
      checkCallback();
    } else {
      if (counter++ < 50) {
        log.info(System.currentTimeMillis() + " WAITING " + counter * 100 + " milliseconds");
        try {
          Thread.sleep(counter * 100);
        } catch (InterruptedException e) {
          // intentionally left empty
        }

        tryToInitialize(counter);
      }
    }
  }
Ejemplo n.º 11
0
  public static void main(String[] args)
      throws ConfigException, InitializationException, InterruptedException {
    System.out.println("STARTED");

    config.load();
    Tray tray = Tray.getInstance();
    tray.registerProcess(tray.getClass().getSimpleName());
    tray.init("Everything is up to date.");

    // File imageFile = null;
    File imageFile = new File(config.getResDir() + File.separator + "logo48.png");
    tray.notify("hello asdas dasd dasd asd ", "test asdsad sd asd sa", imageFile);
    // tray.setStatus(Status.UPDATING);
    tray.addTrayEventListener(
        new TrayEventListener() {

          @Override
          public void trayEventOccurred(TrayEvent event) {
            System.out.println(event);
          }
        });
    tray.setStatusIcon(tray.getClass().getSimpleName(), StatusIcon.UPDATING);
    // System.out.println(FileUtil.showBrowseDirectoryDialog());

    Thread.sleep(5000);
  }
Ejemplo n.º 12
0
  @Override
  public void connect(final String commPort, final String commSpeed) {
    try {
      synchronized (_mutex) {
        _comPortId = CommPortIdentifier.getPortIdentifier(commPort);
        _serialPort = (SerialPort) _comPortId.open("ComPort", 2000);
        _inputStream = _serialPort.getInputStream();
        _outputStream = _serialPort.getOutputStream();
        _serialPort.addEventListener(new MySerialCommPortEventListener());
        _serialPort.notifyOnDataAvailable(true);
        final int speed = Integer.parseInt(commSpeed);
        _serialPort.setSerialPortParams(
            speed, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
        _connected = true;
        Thread.sleep(3000);
        notifyConnectionStatus(true);

        _connectionThread.start();
      }
    } catch (Exception e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }
  }
Ejemplo n.º 13
0
 public void run() {
   for (; ; ) {
     for (; ; ) {
       synchronized (StatisticsPanel.this) {
         if (!running) {
           try {
             StatisticsPanel.this.wait();
           } catch (InterruptedException ex) {
             if (logger.isInfoEnabled()) logger.info("Interrupted...", ex);
             return;
           }
         } else {
           break;
         }
       }
     }
     SwingUtilities.invokeLater(new SwingUpdateRunnable());
     try {
       Thread.sleep(REFRESH_DELAY);
     } catch (InterruptedException ex) {
       if (logger.isInfoEnabled()) logger.info("Interrupted...", ex);
       return;
     }
   }
 }
Ejemplo n.º 14
0
  @Override
  protected Void doInBackground() throws Exception {
    Random random = new Random();
    int progress = 0;
    System.out.println("Start");
    // Initialize progress property.
    setProgress(0);
    while (progress < 100) {
      if (thread.length() == -1) {
        form.errorLabel.setText(thread.getURLString());
        break;
      }
      // Sleep for up to one second.
      try {
        Thread.sleep(random.nextInt(10));
      } catch (InterruptedException ignore) {
      }
      System.out.println(
          thread.numberOfBytes() + "----" + (thread.length() / 100) + "----" + progress);
      // Make random progress.
      if (thread.length() != 0 && (thread.numberOfBytes() / (thread.length() / 100) > progress)) {

        System.out.println("uvelichavame!" + progress);
        progress++;
        // progress =(int)(thread.numberBytes % (thread.length / 100));
        setProgress(Math.min(progress, 100));
      }
    }
    return null;
  }
Ejemplo n.º 15
0
 // set max_frames to 1 for 5 seconds then move up to 200
 public void run() {
   pg.si("frames", 1);
   try {
     Thread.sleep(5000);
   } catch (Exception e) {
     e.printStackTrace();
   }
   for (int i = 1; i <= 100; i++) {
     pg.si("frames", 2 * i);
     try {
       Thread.sleep(10);
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
Ejemplo n.º 16
0
 private static void sleep(int duration, TimeUnit unit) {
   try {
     Thread.sleep(unit.toMillis(duration));
   } catch (InterruptedException e) {
     throw new IllegalStateException("interrupted!");
   }
 }
Ejemplo n.º 17
0
  public void run() {
    MOVE_PREV = MOVE_DOWN;

    System.out.println("INIT!");
    map = new int[mapX][mapY];

    for (int i = 0; i < map.length; i++) {
      for (int j = 0; j < map[i].length; j++) {
        map[i][j] = 0;
      }
    }
    map[blockP.x][blockP.y] = 1;
    //    	map[0][20] = 1;

    StdDraw.setXscale(-1.0, 1.0);
    StdDraw.setYscale(-1.0, 1.0);

    // initial values

    // double vx = 0.015, vy = 0.023;     // velocity

    // main animation loop
    while (true) {

      drawGame();
      try {
        Thread.sleep(100);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      movePrev();
    }
  }
Ejemplo n.º 18
0
  public void jButton4_actionPerformed(ActionEvent e) {
    if (rtc != null) {
      boolean b =
          rtc.SendSelfDefinedMsg(
              Integer.parseInt(txt_AppID.getText()),
              txt_zdljdz.getText().toCharArray(),
              Integer.parseInt(txt_gyh.getText()),
              Integer.parseInt(txt_txfs.getText()),
              Integer.parseInt(txt_mlxh.getText()),
              txt_content.getText().length(),
              txt_content.getText().toCharArray(),
              0);
      try {
        Thread.sleep(1000);
      } catch (InterruptedException ex) {
      }
      rtc.SendSelfDefinedMsg(
          Integer.parseInt(txt_AppID.getText()) + 100,
          txt_zdljdz.getText().toCharArray(),
          Integer.parseInt(txt_gyh.getText()),
          Integer.parseInt(txt_txfs.getText()),
          Integer.parseInt(txt_mlxh.getText()),
          txt_content.getText().length(),
          txt_content.getText().toCharArray(),
          0);

      if (b) {
        System.out.println("send success!");
      } else {
        System.out.println("send fail!");
      }
    } else {
      System.out.println("no object,create it first");
    }
  }
Ejemplo n.º 19
0
  public String set_new_node(String nodex) {

    System.out.println("Add new node");

    while (network.database_in_use == 1) {

      int test_db = 0;
      System.out.println("Database in use... import node");
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
      }
      test_db++;
    } // *********************************

    mining.mining3 = false;

    krypton_database_nodes add_node = new krypton_database_nodes(nodex);

    krypton_database_load_network nodesx = new krypton_database_load_network();

    krypton_database_load loadx = new krypton_database_load();

    mining.mining3 = true;

    return Integer.toString(network.network_list.size());
  } // **********************
Ejemplo n.º 20
0
  public String delete_all_nodes() {

    System.out.println("Delete all nodes");

    while (network.database_in_use == 1) {

      int test_db = 0;
      System.out.println("Database in use... delete all nodes");
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
      }
      test_db++;
    } // *********************************

    mining.mining3 = false;

    krypton_database_delete_network pxd = new krypton_database_delete_network();

    krypton_database_load_network nodesx = new krypton_database_load_network();

    krypton_database_load loadx = new krypton_database_load();

    mining.mining3 = true;

    return "deleted";
  } // **********************
Ejemplo n.º 21
0
  @Override
  public void run() {

    try {
      if (Fecs.getApplicationContext() == null) return;

      Long currentTime = System.currentTimeMillis();
      double deltaTime = (currentTime - lastUpdateTime) * 0.001;

      if (getEngineState() == STATE_START) { // last bit is 1 = started
        int s = getCircumstanceState() - 1; // 0 is null state(error)
        if (s >= CircumstanceType.values().length || s < 0)
          throw new Exception("unstable state value with " + String.valueOf(s));
        Circumstance.get(CircumstanceType.values()[s])
            .setParameter("currentTime", currentTime)
            .setParameter("deltaTime", deltaTime)
            .trigger();
        for (Cabin cabin : cabins.values()) updateCabin(cabin, deltaTime);
      }

      lastUpdateTime = currentTime;

      draw();
    } catch (Exception e) {
      logger.error(e.getMessage(), e);
    } finally {
      try {
        Thread.sleep(1);
      } catch (InterruptedException e) {
        logger.error(e.getMessage(), e);
      }
      SwingUtilities.invokeLater(this);
    }
  }
Ejemplo n.º 22
0
 private void saveButtonActionPerformed() {
   if (getChannel() == null || getKey() == null) {
     setTitle("Please Login First!");
     return;
   }
   playingGameToggle.setSelected("".equals(gameText.getText()));
   Response r =
       APIRequests.Twitch.setStatusOfStream(
           getKey().getKey(),
           getChannel(),
           titleText.getText(),
           gameText.isEnabled() ? gameText.getText() : "");
   if (r.isSuccessful()) {
     setTitle("Status successfully updated!");
     if (!gameText.isEnabled()) gameText.setText("");
   } else {
     setTitle("Status failed to update!");
   }
   ThreadEngine.submit(
       () -> {
         try {
           Thread.sleep(5000);
           setTitle("Change Stream Status");
         } catch (InterruptedException ignored) {
         }
       });
 }
Ejemplo n.º 23
0
 public void jButton12_actionPerformed(ActionEvent e) {
   List<TerminalInfoStruct> TerminalInfo = new LinkedList<TerminalInfoStruct>();
   List<DataContentStruct> DataContentInfo = new LinkedList<DataContentStruct>();
   for (int i = 0; i < 50; i++) {
     TerminalInfo.clear();
     DataContentInfo.clear();
     TerminalInfoStruct tis = new TerminalInfoStruct();
     int l = 91010001 + i;
     String s = Integer.toString(l);
     tis.TerminalAddress =
         ("" + s.substring(0, 4) + s.substring(6, 8) + s.substring(4, 6)).toCharArray();
     tis.TerminalCommType = 40;
     tis.TerminalProtocol = 80;
     TerminalInfo.add(tis);
     DataContentStruct dcs = new DataContentStruct();
     dcs.DataContentLength = txt_content.getText().length();
     dcs.DataContent = txt_content.getText().toCharArray();
     DataContentInfo.add(dcs);
     rtc.SendBatchToFep(
         Integer.parseInt(txt_AppID.getText()),
         TerminalInfo.size(),
         TerminalInfo,
         DataContentInfo,
         txt_gnm.getText().toCharArray(),
         0,
         0,
         0,
         0);
     try {
       Thread.sleep(1000);
     } catch (InterruptedException ex) {
     }
   }
 }
Ejemplo n.º 24
0
 /** @param args */
 public static void main(String[] args) {
   // TODO Auto-generated method stub
   try {
     Connexion conn = new Connexion();
     conn.Connect();
     FilConnexion fil = new FilConnexion(conn);
     fil.start();
     for (int i = 0; i < 5; i++) {
       conn.SendGet();
       System.out.println("GET SENT!");
       Thread.sleep(500);
     }
     fil.interrupt();
     conn.EndConnection();
     System.out.println("FINI!");
   } catch (UnknownHostException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
   // new BackToJava();
   catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 25
0
  private boolean connectSPPMon() {
    if (state == ConnectionEvent.CONNECTION_PENDING) {
      ExpCoordinator.print(
          new String("NCCPConnection(" + host + ", " + port + ").connect connection pending"), 0);
      while (state == ConnectionEvent.CONNECTION_PENDING) {
        try {
          Thread.sleep(500);
        } catch (java.lang.InterruptedException e) {
        }
      }
      return (isConnected());
    }

    state = ConnectionEvent.CONNECTION_PENDING;
    if (nonProxy != null) {
      try {
        nonProxy.connect();
      } catch (UnknownHostException e) {
        boolean rtn = informUserError("Don't know about host: " + host + ":" + e.getMessage());
        return rtn;
      } catch (SocketTimeoutException e) {
        boolean rtn = informUserError("Socket time out for " + host + ":" + e.getMessage());
        return rtn;
      } catch (IOException e) {
        boolean rtn = informUserError("Couldnt get I/O for " + host + ":" + e.getMessage());
        return rtn;
      }
    }
    return (isConnected());
  }
Ejemplo n.º 26
0
  public void testEmptyHeader() {
    fFrame = new JFrame("Test Window");

    // Create a panel to hold all other components
    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BorderLayout());

    // Create a new table instance
    MyTableModel myModel = new MyTableModel();
    fTable = new JTable(myModel);

    // Add the table to a scrolling pane
    JScrollPane scrollPane = new JScrollPane(fTable);
    topPanel.add(scrollPane, BorderLayout.CENTER);

    fFrame.getContentPane().setLayout(new BorderLayout());
    fFrame.getContentPane().add(BorderLayout.CENTER, topPanel);

    fFrame.setSize(400, 450);
    fFrame.setLocation(20, 20);
    fFrame.setVisible(true);
    try {
      Thread.sleep(500);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    JTableHeader header = fTable.getTableHeader();
    assertTrue(
        "JTableHeader greater than 5 pixels tall with empty string first element.",
        header.getSize().height > 5);
    fFrame.setVisible(false);
    fFrame.dispose();
  }
Ejemplo n.º 27
0
 private void leuchten(JLabel label, String farbe) {
   try {
     if (!leuchten) {
       Thread.sleep(200);
       label.setIcon(new ImageIcon(farbe + "_0.png"));
       Thread.sleep(200);
       label.setIcon(new ImageIcon(farbe + "_1.png"));
       Thread.sleep(200);
       label.setIcon(new ImageIcon(farbe + "_0.png"));
       Thread.sleep(200);
       label.setIcon(new ImageIcon(farbe + "_1.png"));
       leuchten = true;
     }
   } catch (Exception e) {
   }
 }
Ejemplo n.º 28
0
  public static void main(String[] args) {
    JmeFormatter formatter = new JmeFormatter();

    Handler consoleHandler = new ConsoleHandler();
    consoleHandler.setFormatter(formatter);

    Logger.getLogger("").removeHandler(Logger.getLogger("").getHandlers()[0]);
    Logger.getLogger("").addHandler(consoleHandler);

    createCanvas(appClass);

    try {
      Thread.sleep(500);
    } catch (InterruptedException ex) {
    }

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            JPopupMenu.setDefaultLightWeightPopupEnabled(false);

            createFrame();

            currentPanel.add(canvas, BorderLayout.CENTER);
            frame.pack();
            startApp();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
          }
        });
  }
Ejemplo n.º 29
0
 /**
  * Wait for a specified number of milliseconds before finishing. This provides an easy way to
  * specify a small delay which can be used when producing animations.
  *
  * @param milliseconds the number
  */
 public void wait(int milliseconds) {
   try {
     Thread.sleep(milliseconds);
   } catch (Exception e) {
     // ignoring exception at the moment
   }
 }
Ejemplo n.º 30
0
  /*This method runs the actual playing part of the game. It goes in a loop while game is true and constantly paints the game,
  requests the focus, checks for collisions, and checks if anyone won with a small delay. If game is false, it leaves the loop and the game is done.*/
  public void game() // constantly runs update and paint world
      {
    // Loops while game is true
    while (game) {
      // Paints the game
      paintGame();

      // Requests the focus for listening to key events
      window.requestFocus();

      // Checks if any player has collided with anything
      checkCollision();

      // Checks if any player has won
      checkWin();

      // Sleeps for SPEED milliseconds
      try {
        Thread.sleep(SPEED);
      } // delay
      catch (InterruptedException e) {
      }

      // Checks if window closed. If so, game is false
      if (!isVisible()) {
        game = false;
      }
    }

    // Makes the mode 5 so that it still stays on the game screen after game is done
    mode = 5;

    // Paints the game once more
    paintGame();
  }