/** Fires weapons when left mouse is pressed */ public void mousePressed(MouseEvent evt) { int mx = evt.getX(); // x-coordinate where user clicked. int my = evt.getY(); // y-coordinate where user clicked. if (!pause) { if (!evt.isMetaDown()) { if (weapons[guntrack].equals("gun") && bshoot) { weaponList.add( new Bullet( mx, my, character.getX(), character.getY(), 0, THA.WIDTH, 0, THA.HEIGHT, 7)); bshoot = false; ammo.useBullet(); bulletTime.restart(); } if (weapons[guntrack].equals("grenade") && gshoot) { weaponList.add( new Grenade( mx, my, character.getX(), character.getY(), 0, THA.WIDTH, 0, THA.HEIGHT, 12)); gshoot = false; ammo.useGrenade(); grenadeTime.restart(); } if (weapons[guntrack].equals("laser") && lshoot) { weaponList.add( new Laser( mx, my, character.getX(), character.getY(), 0, THA.WIDTH, 0, THA.HEIGHT, 20)); lshoot = false; ammo.useLaser(); laserTime.restart(); } if (weapons[guntrack].equals("shotgun") && sgshoot) { weaponList.add( new ShotGun( mx, my, character.getX(), character.getY(), 0, THA.WIDTH, 0, THA.HEIGHT, 7, character.getX(), character.getY(), 25, 90, weaponList)); sgshoot = false; ammo.useShotgun(); shotgunTime.restart(); } } } }
/** * 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(); }
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))); }
public void rebuildTreeLater() { if (myTimer.isRunning()) { return; } else { myTimer.restart(); } }
protected final void restartTimer() { if (!myAutoSelectionTimer.isRunning()) { myAutoSelectionTimer.start(); } else { myAutoSelectionTimer.restart(); } }
public void testRestartWithNewLimit() throws Exception { Timer timer = new Timer(new TimeAmount(10000L)); timer.start(new TimeInstant(0L)); timer.restart(new TimeInstant(1000L), new TimeAmount(20000L)); assertEquals(new TimeAmount(19000L), timer.getRemainingTime(new TimeInstant(2000L))); assertEquals(new TimeAmount(10000L), timer.getRemainingTime(new TimeInstant(11000L))); assertEquals(new TimeAmount(9000L), timer.getRemainingTime(new TimeInstant(12000L))); assertEquals(new TimeAmount(-1000L), timer.getRemainingTime(new TimeInstant(22000L))); }
public void loadConfiguration(Configuration configuration) { imagesList.clear(); String directory = configuration.getDirectory(); int maxSize = ImageHolder.coerceInteger(configuration.getMaxSize()); if (directory != null && !directory.isEmpty()) { File dir = new File(directory); File[] files = dir.listFiles( new FilenameFilter() { @Override public boolean accept(File dir, String name) { String lowerName = name.toLowerCase(); return lowerName.endsWith(".jpg") || lowerName.endsWith(".png") || lowerName.endsWith(".gif"); } }); if (files != null && files.length > 0) { imagesList.ensureCapacity(files.length); for (File file : files) { if (file.isFile()) { imagesList.add(new ImageHolder(file, maxSize)); } } imagesList.trimToSize(); } } boolean useTimer = configuration.isUseTimer(); if (useTimer) { if (timer.isRunning()) { timer.restart(); } else { timer.start(); } } else { if (timer.isRunning()) { timer.stop(); } } for (Editor editor : editorsList) { loadImage(editor); } }
/** Restarts the timer every time the text changes. */ public void textChanged() { timer.restart(); }
public void start() { timer.restart(); }
public void actionPerformed(ActionEvent e) { Object src = e.getSource(); if (src == timer) { for (int i = 0; i < speed; i++) // integrate a few steps md.vv(); repaint(); return; } boolean adjCanvasScale = false; if (src == bTstat) md.thermostat = !md.thermostat; if (src == bPot) { md.ljPotential = !md.ljPotential; md.clearData(); if (timer.isRunning()) timer.stop(); bStart.setSelected(false); bStart.setText("Start"); md.init(md.rho); } if (src == tTemp || src == bReset) { double kT = Double.parseDouble(tTemp.getText().trim()); if (kT < 1e-8) { kT = 1e-8; tTemp.setText(" " + kT); } md.kT = kT; md.clearData(); } if (src == tRho || src == bReset) { double rho = Double.parseDouble(tRho.getText().trim()); if (rho < 1e-3) { rho = 1e-3; tRho.setText(" " + rho); } if (rho > 1.2) { rho = 1.2; tRho.setText(" " + rho); } md.setDensity(rho); md.clearData(); adjCanvasScale = true; } if (src == tSpeed || src == bReset) { speed = Integer.parseInt(tSpeed.getText().trim()); if (speed < 1) { speed = 1; tSpeed.setText(" " + speed); } } if (src == bRetime) md.clearData(); if (src == bStart) { boolean on = bStart.isSelected(); if (on) { timer.restart(); bStart.setText("Pause"); } else { timer.stop(); bStart.setText("Resume"); } } if (src == tNum) { int n = Integer.parseInt(tNum.getText().trim()); if (n < 2) { n = 2; tNum.setText(" " + n); } md.N = n; md.init(md.rho); adjCanvasScale = true; } if (src == bReset) { if (timer.isRunning()) timer.stop(); bStart.setSelected(false); bStart.setText("Start"); md.init(md.rho); } canvas.refresh(md.getXWrap(), md.N, true, adjCanvasScale); repaint(); }