示例#1
0
  /** load all brain categories from AIMLIF directory */
  public int addCategoriesFromAIMLIF() {
    Timer timer = new Timer();
    timer.start();
    int cnt = 0;

    try {
      String[] listOfFiles = Alice.getContext().getAssets().list(aimlif_path);
      if (MagicBooleans.trace_mode) System.out.println("Loading AIML files from " + aimlif_path);
      for (String file : listOfFiles) {
        if (file.endsWith(MagicStrings.aimlif_file_suffix)
            || file.endsWith(MagicStrings.aimlif_file_suffix.toUpperCase())) {
          if (MagicBooleans.trace_mode) System.out.println(file);
          try {
            ArrayList<Category> moreCategories = readIFCategories(aimlif_path + "/" + file);
            cnt += moreCategories.size();
            addMoreCategories(file, moreCategories);
            //   MemStats.memStats();
          } catch (Exception iex) {
            System.out.println("Problem loading " + file);
            iex.printStackTrace();
          }
        }
      }

    } catch (IOException e) {
      e.printStackTrace();
    }

    if (MagicBooleans.trace_mode)
      System.out.println("Loaded " + cnt + " categories in " + timer.elapsedTimeSecs() + " sec");
    return cnt;
  }
示例#2
0
  public void newGame() {

    gameObject1.clear();
    gameObject2.clear();
    gameObject3.clear();
    gameObject4.clear();

    gameObjectadd();
    timer.resetTimer();
    score1 = 0;
    score2 = 0;
    totalWinner = 0;
    winner = 0;
    money.randomize();
    state = 1;
    round = 0;
    choose = "Nope";
    choose2 = "Nope";
    newMoney(scaledMoney, money.drawUpdate(money.vals[0]));
    newMoney(Money1, score11.drawUpdate(0));
    newMoney(Money2, score22.drawUpdate(0));
    newMoney(scaledTimer, timer.drawUpdate());

    score11.setBitmap(Money1.get(0), Money1.get(1));
    score22.setBitmap(Money2.get(0), Money2.get(1));
    money.setBitmap(scaledMoney.get(0), scaledMoney.get(1));
    timer.setBitmap(scaledTimer.get(0), scaledTimer.get(1));
  }
示例#3
0
 public void setGertrudeVsComputer() {
   typeOfGame = "Gertrudis vs Computer";
   typeOfGameTimer = new Timer(IMAGE_LOADERS_TIMER, this);
   typeOfGameTimer.setActionCommand("Gertrude vs Computer");
   typeOfGameTimer.setRepeats(false); // occurs only one time
   typeOfGameTimer.start();
 }
示例#4
0
  public static void main(String[] args) {
    System.out.println("Blinking LED");

    System.out.println("System clock = " + AVR.getClock() + "000 Hz");

    // both led ports are outputs
    AVR.portB.setOutput(0);
    AVR.portB.setOutput(1);

    // no need to setup timer, since 100Hz is default ...

    while (true) {
      // PortB.0/1 for Demoboard
      AVR.portB.setBit(1);
      AVR.portB.setBit(0);
      Timer.wait(100);
      AVR.portB.clrBit(0);
      Timer.wait(100);

      AVR.portB.clrBit(1);
      AVR.portB.setBit(0);
      Timer.wait(100);
      AVR.portB.clrBit(0);
      Timer.wait(100);
    }
  }
示例#5
0
  public void gameover() {
    ImageIcon bombss = new ImageIcon("bomb.png");
    for (int i = 0; i < row; i++) {
      for (int j = 0; j < col; j++) {
        if (bombs[i][j] == true) {
          gbuttons[i][j].setBackground(Color.red);

          gbuttons[i][j].setIcon(bombss);
        }
      }
    }

    int delay = 2000; // milliseconds
    ActionListener taskPerformer =
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            Lost lost = new Lost();
            lost.setLocationRelativeTo(null);
            lost.setVisible(true);
            dispose();
          }
        };
    Timer timer = new Timer(delay, taskPerformer);
    timer.setRepeats(false);
    timer.start();
  }
 /**
  * Expands or collapses this <code>JCollapsiblePane</code>.
  *
  * <p>
  *
  * <p>If the component is collapsed and <code>val</code> is false, then this call expands the
  * JCollapsiblePane, such that the entire JCollapsiblePane will be visible. If {@link
  * #isAnimated()} returns true, the expansion will be accompanied by an animation.
  *
  * <p>
  *
  * <p>However, if the component is expanded and <code>val</code> is true, then this call collapses
  * the JCollapsiblePane, such that the entire JCollapsiblePane will be invisible. If {@link
  * #isAnimated()} returns true, the collapse will be accompanied by an animation.
  *
  * @javabean.property bound="true" preferred="true"
  * @see #isAnimated()
  * @see #setAnimated(boolean)
  */
 public void setCollapsed(boolean val) {
   if (collapsed != val) {
     collapsed = val;
     if (isAnimated()) {
       if (collapsed) {
         setAnimationParams(
             new AnimationParams(30, Math.max(8, wrapper.getHeight() / 10), 1.0f, 0.01f));
         animator.reinit(wrapper.getHeight(), 0);
         animateTimer.start();
       } else {
         setAnimationParams(
             new AnimationParams(
                 30, Math.max(8, getContentPane().getPreferredSize().height / 10), 0.01f, 1.0f));
         animator.reinit(wrapper.getHeight(), getContentPane().getPreferredSize().height);
         animateTimer.start();
       }
     } else {
       wrapper.c.setVisible(!collapsed);
       invalidate();
       doLayout();
     }
     repaint();
     firePropertyChange("collapsed", !collapsed, collapsed);
   }
 }
  /*
   * reads the value of the digital input of the specified channel
   * requires that the readArudiono() method has already been called
   * param 1: the channel to be read
   * return: value of the specified digital input
   */
  public boolean getInput(int channelID) {
    byte temp;

    if (timer.get() > 2.0) {
      DriverStationLCD.getInstance()
          .println(DriverStationLCD.Line.kUser3, 1, "                     ");
      DriverStationLCD.getInstance().updateLCD();
      timer.stop();
      timer.reset();
    }

    if (Math.abs(channelID - (13 / 2)) - (13 / 2)
        > 0) // returns true if less than zero or greater than thirteen
    {
      timer.start();
      DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser3, 1, "Invalid ID");
      DriverStationLCD.getInstance().updateLCD();
      return false;
    } else if (channelID < 8) {
      temp = (byte) (loByte & (1 << channelID));
      return temp != 0;
    } else {
      temp = (byte) (hiByte & (1 << channelID - 8));
      return temp != 0;
    }
  }
示例#8
0
 protected final void restartTimer() {
   if (!myAutoSelectionTimer.isRunning()) {
     myAutoSelectionTimer.start();
   } else {
     myAutoSelectionTimer.restart();
   }
 }
 public void change(String url) {
   log.info("Change to " + url);
   SwingUtilities.invokeLater(
       () -> {
         if (url == null) {
           currentUrl = null;
           stop();
           return;
         }
         ready = false;
         PlayerInImage player2 = new PlayerInImage(width, height, null, url);
         Timer timer =
             new Timer(
                 sleepTime,
                 (a) -> {
                   JComponent component = player.getComponent();
                   player.setComponent(null);
                   player2.setComponent(component);
                   inChange = true;
                   player.stop();
                   player = player2;
                   image = player2.getImage();
                   ready = true;
                   currentUrl = url;
                 });
         timer.setRepeats(false);
         timer.start();
       });
 }
示例#10
0
 private void jBFecharActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jBFecharActionPerformed
   // TODO add your handling code here:
   this.setVisible(false);
   timerPCP.start();
   timer.stop();
 } // GEN-LAST:event_jBFecharActionPerformed
示例#11
0
  @Override
  protected Void doInBackground() throws Exception {
    Timer sleuthRunTime = new Timer(System.nanoTime());
    iterationsRemaining = iterations;
    for (int i = 0; i < iterations; i++) {
      try {
        String output = "Running SLEUTH, iteration " + (i + 1) + " of " + iterations;

        Process proc = new ProcessBuilder(rootPath + "\\grow.exe", "predict", scenPath).start();
        BufferedReader input = new BufferedReader(new InputStreamReader(proc.getInputStream()));
        while (input.readLine() != null) {
          // console.println(input.readLine());
        }
        proc.waitFor();
        img = ImageAnalysis.openImageFile(img, outputDir, endYear, scenName);
        this.setTotalPixels(img.getHeight() * img.getWidth());
        publish(output);
        publish("" + this.getTotalTimeRemaining());
        publish("" + this.getTotalEstimatedTime());
        ImageAnalysis.analyzeImageFile(img, i, fullDataPath, seedDataPath);
      } catch (IOException e) {
        e.printStackTrace();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      iterationsRemaining--;
    }
    this.addTotalTime(sleuthRunTime.time());
    return null;
  }
示例#12
0
  private void create() {
    JFrame f = new JFrame("JSplitPane");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    MyPanel p1 = new MyPanel(Color.red);
    MyPanel p2 = new MyPanel(Color.blue);
    final JSplitPane jsp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, p1, p2);
    Timer timer =
        new Timer(
            200,
            new ActionListener() {

              @Override
              public void actionPerformed(ActionEvent e) {
                ratio += delta;
                if (ratio >= 1.0) {
                  ratio = 1.0;
                  delta = -delta;
                } else if (ratio <= 0) {
                  delta = -delta;
                  ratio = 0;
                }
                jsp.setDividerLocation(ratio);
              }
            });

    f.add(jsp);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
    timer.start();
  }
示例#13
0
  /** Load all AIML Maps */
  int addAIMLMaps() {
    int cnt = 0;
    Timer timer = new Timer();
    timer.start();

    try {
      String[] listOfFiles = Alice.getContext().getAssets().list(maps_path);
      if (MagicBooleans.trace_mode) {
        System.out.println("Loading AIML Map files from " + maps_path);
        BrainLogger.getInstance().info("Loading AIML Map files from " + maps_path);
      }

      for (String file : listOfFiles) {

        if (file.endsWith(".txt") || file.endsWith(".TXT")) {
          if (MagicBooleans.trace_mode) System.out.println(file);
          String mapName = file.substring(0, file.length() - ".txt".length());
          if (MagicBooleans.trace_mode) System.out.println("Read AIML Map " + mapName);
          AIMLMap aimlMap = new AIMLMap(mapName, this);
          cnt += aimlMap.readAIMLMap(this);
          mapMap.put(mapName, aimlMap);
        }
      }
    } catch (IOException e) {
      System.out.println("addAIMLMaps: " + maps_path + " does not exist.");
      e.printStackTrace();
    }

    return cnt;
  }
 public void autonomousPeriodic() {
   relay.set(Relay.Value.kOn);
   smart.putNumber("distance", ultrasonic.getVoltage());
   drive.setRun(false);
   loadAndShoot.setRun(false);
   //    relay.set(Relay.Value.kOn);
   if (autoTimer.get() < autoMoveForwardTime) {
     System.out.println(
         "Moving forward, Timer at "
             + autoTimer.get()
             + ", Ultrasonic at "
             + ultrasonic.getAverageVoltage());
   }
   if (autoTimer.get() >= autoMoveForwardTime && ultrasonic.getAverageVoltage() <= AUTO_DISTANCE) {
     stop();
     if (!autonomousStopped) {
       autonomousStopped = true;
       autoTimeAtStop = autoTimer.get();
     }
     System.out.println("Stopped, Ultrasonic at " + ultrasonic.getAverageVoltage());
   }
   if (autoTimer.get() >= autoTimeAtStop + 1 && ultrasonic.getAverageVoltage() <= AUTO_DISTANCE) {
     autoStop = true;
     shoot();
     System.out.println("Shooting, Ultrasonic at " + ultrasonic.getAverageVoltage());
   }
 }
示例#15
0
  /** This is called by the ProtolibTimer */
  public void timeOut() {
    logger.trace("javm/util/TimerTask: timeOut entered");
    if (state == CANCELLED) {
      logger.trace("javm/util/TimerTask: I have been cancelled -- timeOut left");
      timer.removeTimerTask(this);
      return;
    }

    Controller controller = AgentJVirtualMachine.getCurrentNS2NodeController();
    run();
    logger.trace("TimerTask.java: run() left");

    if (period != 0) {
      logger.trace("javm/util/TimerTask: new Timer created");
      nextExecutionTime += Math.abs(period);
      ProtolibTimer protoTimer =
          new ProtolibTimer(controller, (double) Math.abs(period) / 1000.0, 0);
      protoTimer.startTimerAndNotifyOnTimeout(this);
      logger.trace("javm/util/TimerTask: new Timer created sucessfully");
    } else { // non-repeating task
      state = EXECUTED;
      timer.removeTimerTask(this);
    }
    logger.trace("javm/util/TimerTask: timeOut left");
  }
  /**
   * Attempts to search the mod website for the mod and pull the recent versions of the mod.
   *
   * @param mod The Mod to search for on the website.
   * @param modInfoList The JList to populate/alter.
   */
  public void getRecentVersionsOfModAsync(Profile.Mod mod, JList modInfoList) {
    // Here we set a thread task to get the version numbers for the mod. This will look at the site
    // and search for the mod, then pull all versions from it.
    Runnable task = () -> Crawler.readVersionInfoOfMod(mod.nameWithoutVersion);
    Thread thread = new Thread(task);
    thread.start();

    // Our timer that checks every 200ms if the thread has finished.
    Timer timer = new Timer(200, null);
    timer.addActionListener(
        ev -> {
          if (thread.getState() != Thread.State.TERMINATED) timer.restart();
          else {
            timer.stop();
            DefaultListModel listModel = (DefaultListModel) modInfoList.getModel();
            // Get the modVersionInfo from the crawler. If not null, add to the list.
            String[][] modVersionInfo = Crawler.getModVersionInfo();
            if (modVersionInfo != null) {
              listModel.addElement("Recent Versions:");
              for (String[] info : modVersionInfo) {
                listModel.addElement("    v" + info[0] + " for " + info[1]);
              }
            } else {
              listModel.addElement("Couldn't find the mod on the website.");
            }
            modInfoList.setModel(listModel);
          }
        });
    timer.start();
  }
示例#17
0
 public void testGetRemainingTime() throws Exception {
   Timer timer = createTimer();
   timer.restart(new TimeInstant(0L));
   assertEquals(new TimeAmount(9000L), timer.getRemainingTime(new TimeInstant(1000L)));
   assertEquals(new TimeAmount(0L), timer.getRemainingTime(new TimeInstant(10000L)));
   assertEquals(new TimeAmount(-1000L), timer.getRemainingTime(new TimeInstant(11000L)));
 }
示例#18
0
 public void rebuildTreeLater() {
   if (myTimer.isRunning()) {
     return;
   } else {
     myTimer.restart();
   }
 }
示例#19
0
  /**
   * Checks for an auto scroll event. This should be called when a drag & drop operation is in
   * progress and the drop target is inside a scroll pane.
   *
   * @param evt the mouse event which should be checked.
   * @return true if auto scrolling is started/active.
   * @see #stopAutoScroll()
   */
  public boolean checkAutoScroll(Event evt) {
    GUI gui = getGUI();
    if (gui == null) {
      stopAutoScroll();
      return false;
    }

    autoScrollDirection = getAutoScrollDirection(evt);
    if (autoScrollDirection == 0) {
      stopAutoScroll();
      return false;
    }

    setAutoScrollMarker();

    if (autoScrollTimer == null) {
      autoScrollTimer = gui.createTimer();
      autoScrollTimer.setContinuous(true);
      autoScrollTimer.setDelay(AUTO_SCROLL_DELAY);
      autoScrollTimer.setCallback(
          new Runnable() {
            public void run() {
              doAutoScroll();
            }
          });
      doAutoScroll();
    }
    autoScrollTimer.start();
    return true;
  }
示例#20
0
  public Clock() {

    main_panel.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            System.exit(0);
          }
        });

    Timer timer =
        new Timer(
            1000,
            new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                Calendar curTime = Calendar.getInstance();
                curTime.setTimeInMillis(System.currentTimeMillis());

                hour.setText(setTimeString(curTime.get(Calendar.HOUR_OF_DAY) + ""));
                minutes.setText(setTimeString(curTime.get(Calendar.MINUTE) + ""));
                second.setText(setTimeString(curTime.get(Calendar.SECOND) + ""));
              }
            });
    timer.setInitialDelay(0);
    timer.start();
  }
示例#21
0
  @Override
  public void surfaceCreated(SurfaceHolder holder) {
    scaleFactorX = getWidth() / (WIDTH * 1.f);
    scaleFactorY = getHeight() / (HEIGHT * 1.f);

    createPics();

    scaledMoney.add(BitmapFactory.decodeResource(getResources(), R.drawable.money));
    scaledMoney.add(BitmapFactory.decodeResource(getResources(), R.drawable.kingword));
    Money1.add(BitmapFactory.decodeResource(getResources(), R.drawable.money));
    Money1.add(BitmapFactory.decodeResource(getResources(), R.drawable.kingword));
    Money2.add(BitmapFactory.decodeResource(getResources(), R.drawable.money));
    Money2.add(BitmapFactory.decodeResource(getResources(), R.drawable.kingword));
    scaledTimer.add(BitmapFactory.decodeResource(getResources(), R.drawable.civilian));
    scaledTimer.add(BitmapFactory.decodeResource(getResources(), R.drawable.captain));

    setupVar();

    newMoney(scaledMoney, money.drawUpdate(money.vals[0]));
    newMoney(Money1, score11.drawUpdate(0));
    newMoney(Money2, score22.drawUpdate(0));
    newMoney(scaledTimer, timer.drawUpdate());

    score11.setBitmap(Money1.get(0), Money1.get(1));
    score22.setBitmap(Money2.get(0), Money2.get(1));
    money.setBitmap(scaledMoney.get(0), scaledMoney.get(1));
    timer.setBitmap(scaledTimer.get(0), scaledTimer.get(1));

    thread = new MainThread(getHolder(), this);
    // we can safely start the game loop
    thread.setRunning(true);
    thread.start();
  }
示例#22
0
 public void startGame() {
   image = createImage(SIZE.width, SIZE.height);
   graph = image.getGraphics();
   for (int i = 0; i < balls.length; i++) balls[i].start();
   Timer timer = new Timer(REFRESH, this);
   timer.start();
 }
示例#23
0
 @Test
 public void buildDefault() throws IOException {
   PropertiesManager pm = Tools.makePm(testFolder, "timeout=1", "step=5");
   Timer t = new Timer(Timer.DEFAULTNAME, pm.timers.get(Timer.DEFAULTNAME));
   Assert.assertEquals("bad timeout", 1, t.getTimeout());
   Assert.assertEquals("bad step", 5, t.getStep());
 }
示例#24
0
 private boolean teleporting(ClientContext ctx) {
   if (ctx.players.local().animation() != -1) {
     t.reset(); // To account for small lag when the map changes and animation becomes -1
     return true;
   }
   return t.isRunning();
 }
示例#25
0
 @Test
 public void testAddObserver() {
   Timer timer = new SimpleTimer();
   MockSimpleTimer observer = new MockSimpleTimer();
   timer.addTimeObserver(observer);
   timer.timeChanged();
   assertEquals(1, observer.myTime);
 }
 public void mouseExited(MouseEvent e) {
   if (!readOnly) {
     lastMouseExitTime = System.currentTimeMillis();
     if (timer != null && timer.isRunning()) {
       timer.stop();
     }
   }
 }
示例#27
0
 @Override
 public void actionPerformed(ActionEvent e) {
   if (tcheck.isSelected()) {
     timer.start();
   } else {
     timer.stop();
   }
 }
示例#28
0
  private void jBFecharActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jBFecharActionPerformed

    timerTelaExclusao.stop();
    timer.start();
    this.setVisible(false);
    atualizar.doClick();
  } // GEN-LAST:event_jBFecharActionPerformed
示例#29
0
 @Override
 public void setLocked(boolean isLocked) {
   super.setLocked(isLocked);
   if (isLocked) {
     timer.start();
   } else {
     timer.stop();
   }
 }
示例#30
-62
 private void createRepaintTimer() {
   if (myRepaintTimer != null) {
     myRepaintTimer.stop();
   }
   myRepaintTimer = new Timer(1000 / myMaxFPS, new WeakRedrawTimer(this));
   myRepaintTimer.start();
 }