public static void main(String... args) throws Exception { Robot robot = new Robot(); SwingUtilities.invokeAndWait( new Runnable() { public void run() { popup = new JPopupMenu(); popup.add(new JMenuItem("item")); popup.setVisible(true); } }); robot.waitForIdle(); if (!popup.isShowing()) { throw new RuntimeException("Where is my popup ?"); } SwingUtilities.invokeAndWait( new Runnable() { public void run() { popup.setVisible(false); popup.removeAll(); popup.setVisible(true); } }); robot.waitForIdle(); if (popup.isShowing()) { throw new RuntimeException("Empty popup is shown"); } popup.setVisible(false); }
@Override public void keyReleased(KeyEvent e) { switch (e.getKeyCode()) { case KeyEvent.VK_UP: robot.stopUp(); break; case KeyEvent.VK_DOWN: robot.stopDown(); break; case KeyEvent.VK_LEFT: myBasket.stopMoving(); break; case KeyEvent.VK_RIGHT: myBasket.stopMoving(); break; /*case KeyEvent.VK_SPACE: break;*/ case KeyEvent.VK_CONTROL: robot.setReadyToFire(true); break; } }
@Override public void paint(Graphics g) { if (state == GameState.Running) { g.drawImage(background, bg1.getBgX(), bg1.getBgY(), this); g.drawImage(background, bg2.getBgX(), bg2.getBgY(), this); paintTiles(g); ArrayList<Projectile> projectiles = robot.getProjectiles(); for (int i = 0; i < projectiles.size(); i++) { Projectile p = (Projectile) projectiles.get(i); g.setColor(Color.YELLOW); g.fillRect(p.getX(), p.getY(), 10, 5); } // g.drawRect((int)robot.rect.getX(), (int)robot.rect.getY(), // (int)robot.rect.getWidth(), (int)robot.rect.getHeight()); // g.drawRect((int)robot.rect2.getX(), (int)robot.rect2.getY(), // (int)robot.rect2.getWidth(), (int)robot.rect2.getHeight()); g.drawImage(currentSprite, robot.getCenterX() - 61, robot.getCenterY() - 63, this); g.drawImage(hanim.getImage(), hb.getCenterX() - 48, hb.getCenterY() - 48, this); g.drawImage(hanim.getImage(), hb2.getCenterX() - 48, hb2.getCenterY() - 48, this); g.setFont(font); g.setColor(Color.WHITE); g.drawString(Integer.toString(score), 740, 30); } else if (state == GameState.Dead) { g.setColor(Color.BLACK); g.fillRect(0, 0, 800, 480); g.setColor(Color.WHITE); g.drawString("Dead", 360, 240); } }
private Action scanArenaColByCol(Robot robot) { Action actionForTentativeTurn = actionForTentiveTurn(robot); if (actionForTentativeTurn != null) return actionForTentativeTurn; if (robotOnArenaEdge(robot, headingOrientation)) { Orientation current = robot.getCurrentOrientation(); if (!current.toOppsite().equals(headingOrientation)) { return Action.TURN_LEFT; } else { headingOrientation = headingOrientation.toOppsite(); trackColID += robot.getDiameterInCellNum(); // Whole arena has been explored if (trackColID >= this.exploredMap.getColumnCount()) return null; } } int currentSouthWestColID = robot.getSouthWestBlock().getColID(); if (currentSouthWestColID < trackColID) { return moveToOrientation(robot, Orientation.EAST, headingOrientation); } else if (currentSouthWestColID == trackColID) { return moveToOrientation(robot, headingOrientation, Orientation.EAST); } else { // currentSouthWestColID > trackColID return moveToOrientation(robot, Orientation.WEST, headingOrientation); } }
@Test public void testToCreateARobotAndPlaceIt() { DIRECTIONS pos = DIRECTIONS.valueOf("NORTH"); xy.setXY(0, 0); robot.place(pos, xy); assertEquals("0,0 NORTH", robot.report()); }
@Override public void keyPressed(KeyEvent e) { switch (e.getKeyCode()) { case KeyEvent.VK_UP: System.out.println("Move up"); break; case KeyEvent.VK_DOWN: System.out.println("Move down"); break; case KeyEvent.VK_LEFT: robot.moveLeft(); break; case KeyEvent.VK_RIGHT: robot.moveRight(); break; case KeyEvent.VK_SPACE: robot.jump(); break; } }
public static void requestFocus(Project project, final boolean useRobot) { JFrame frame = WindowManager.getInstance().getFrame(project); // the only reliable way I found to bring it to the top boolean aot = frame.isAlwaysOnTop(); frame.setAlwaysOnTop(true); frame.setAlwaysOnTop(aot); int frameState = frame.getExtendedState(); if ((frameState & Frame.ICONIFIED) == Frame.ICONIFIED) { // restore the frame if it is minimized frame.setExtendedState(frameState ^ Frame.ICONIFIED); } frame.toFront(); frame.requestFocus(); if (useRobot && runningOnWindows7()) { try { // remember the last location of mouse final Point oldMouseLocation = MouseInfo.getPointerInfo().getLocation(); // simulate a mouse click on title bar of window Robot robot = new Robot(); robot.mouseMove(frame.getX(), frame.getY()); robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); // move mouse to old location robot.mouseMove((int) oldMouseLocation.getX(), (int) oldMouseLocation.getY()); } catch (Exception ex) { // just ignore exception, or you can handle it as you want } finally { frame.setAlwaysOnTop(false); } } }
public void setTwoSides(double left, double right) { left = limit(left); right = limit(right); Scalar leftSpeed = maximumSpeed.multiply(left); Scalar rightSpeed = maximumSpeed.multiply(right); if (leftSpeed.equals(rightSpeed)) { robot.addImpulse(Vector.Axes2D.X.multiply(leftSpeed).multiply(robot.getMass())); } else { Scalar angularVelocity = leftSpeed.subtract(rightSpeed).divide(robot.getWidth()); Scalar gamma = robot .getWidth() .multiply(leftSpeed.add(rightSpeed)) .divide(leftSpeed.subtract(rightSpeed)) .multiply(angularVelocity); Vector velocity = new Vector( -Scalar.sin(robot.getAngularPosition().get(0)), Scalar.cos(robot.getAngularPosition().get(0))) .multiply(gamma); robot.addImpulse(velocity.multiply(robot.getMass())); robot.addAngularImpulse( robot .getMomentOfInertia() .multiplyColumn(new Vector(angularVelocity.multiply(Scalar.RADIAN)))); } }
public static void main(String[] args) throws Exception { UIManager.setLookAndFeel(new NimbusLookAndFeel()); Robot robot = new Robot(); robot.setAutoDelay(50); SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); SwingUtilities.invokeAndWait( new Runnable() { public void run() { createAndShowGUI(); } }); toolkit.realSync(); SwingUtilities.invokeAndWait( new Runnable() { public void run() { Component previewPanel = Util.findSubComponent(cc, "javax.swing.colorchooser.DefaultPreviewPanel"); point = previewPanel.getLocationOnScreen(); } }); point.translate(5, 5); robot.mouseMove(point.x, point.y); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); }
public void uimsg(int id, String msg, Object... args) { Widget w = widgets.get(id); synchronized (robots) { for (Robot r : robots) r.uimsg(id, w, msg, args); } super.uimsg(id, msg, args); }
@Override public void keyReleased(KeyEvent e) { switch (e.getKeyCode()) { case KeyEvent.VK_UP: System.out.println("Stop moving up"); break; case KeyEvent.VK_DOWN: // currentSprite = character; currentSprite = anim.getImage(); robot.setDucked(false); break; case KeyEvent.VK_LEFT: robot.stopLeft(); break; case KeyEvent.VK_RIGHT: robot.stopRight(); break; case KeyEvent.VK_SPACE: break; case KeyEvent.VK_CONTROL: robot.setReadyToFire(true); break; } }
public void newwidget(int id, String type, Coord c, int parent, Object... args) throws InterruptedException { super.newwidget(id, type, c, parent, args); Widget w = widgets.get(id); synchronized (robots) { for (Robot r : robots) r.newwdg(id, w, args); } }
/** * Creates a ScreenShot of the client's desktop of the area provided. * * @param x1 The x value of the top left point. * @param y1 The y value of the top left point. * @param x2 The x value of the bottom right point. * @param y2 The y value of the bottom right point. * @return The image. */ public static BufferedImage captureDesktop(int x1, int y1, int x2, int y2) { try { final Robot robot = new Robot(); return robot.createScreenCapture(new Rectangle(x1, y1, x2, y2)); } catch (AWTException ignored) { return null; } }
public Robot move(Robot robot) { IDirection direction = this.directions.get(robot.getDirection()); int[] coordinates = direction.moveForward(robot.getX(), robot.getY()); moveTo(robot, coordinates[0], coordinates[1]); return robot; }
public Robot clone() { Robot result = new Robot(maze, row, column); result.debug = debug; result.direction = direction; // Add the trip of the ancestors result.visited = new ArrayList<String>(visited); return result; }
// Set if the application is in editing mode based on the state of the shift key public void setEditingMode() { try { Robot robot = new Robot(); robot.keyRelease(KeyEvent.VK_SHIFT); } catch (AWTException e) { e.printStackTrace(); } }
/** * Sets the values. * * @param bot */ public void setValues(double dTime, Robot bot) { setValues( dTime, bot.getMotorLeftSpeed(), bot.getMotorRightSpeed(), bot.getShooterSpeed(), bot.getFeederStatus()); }
@Test public void testToTurnRobotFacingWestAndThenTurnRight() { DIRECTIONS pos = DIRECTIONS.valueOf("WEST"); xy.setXY(0, 0); robot.place(pos, xy); robot.turnRight(); assertEquals("0,0 NORTH", robot.report()); }
@Test public void testToTurnLeftRobotFacingNorth() { DIRECTIONS pos = DIRECTIONS.valueOf("NORTH"); xy.setXY(0, 0); robot.place(pos, xy); robot.turnLeft(); assertEquals("0,0 WEST", robot.report()); }
@Test public void testTomoveRobotFacingSouthAt00() { DIRECTIONS pos = DIRECTIONS.valueOf("SOUTH"); xy.setXY(0, 0); robot.place(pos, xy); robot.move(); assertEquals("0,-1 SOUTH", robot.report()); }
@Test public void testTomoveRobotFacingEastAt00() { DIRECTIONS pos = DIRECTIONS.valueOf("EAST"); xy.setXY(0, 0); robot.place(pos, xy); robot.move(); assertEquals("1,0 EAST", robot.report()); }
@Override public void paint(Graphics g) { if (state == GameState.Running) { // g.drawImage(background, bg1.getBgX(), bg1.getBgY(), this); // g.drawImage(background, bg2.getBgX(), bg2.getBgY(), this); // paintTiles(g); ArrayList projectiles = robot.getProjectiles(); for (int i = 0; i < projectiles.size(); i++) { Projectile p = (Projectile) projectiles.get(i); g.setColor(Color.BLACK); g.fillRect(p.getX(), p.getY(), 35, 2); } for (int i = 0; i < Ballon_Objects.size(); i++) { Ballon bb = Ballon_Objects.get(i); if (bb.isVisible == true) g.drawImage(ballonImage, bb.getCenterX() - 28, bb.getCenterY() - 35, this); else { Ballon_Objects.remove(i); } System.out.println("" + Ballon_Objects.size()); } for (int i = 0; i < Ballon_Bottom_Objects.size(); i++) { BallonBottom bottom = Ballon_Bottom_Objects.get(i); if (bottom.isVisible == true) g.drawImage(ballonBottomImage, bottom.getCenterX() - 10, bottom.getCenterY() + 13, this); else { Ballon_Bottom_Objects.remove(i); } System.out.println("BallonBottom:" + Ballon_Bottom_Objects.size()); } /*g.drawImage(character, robot.getCenterX() - 61, robot.getCenterY() - 63, this); */ g.drawImage(arrowRobot, robot.getCenterX() - 51, robot.getCenterY() - 50, this); g.drawImage(basket, myBasket.getCenterX() - 54, myBasket.getCenterY() - 20, this); /*g.drawImage(hanim.getImage(), hb.getCenterX() - 48, hb.getCenterY() - 48, this); g.drawImage(hanim.getImage(), hb2.getCenterX() - 48, hb2.getCenterY() - 48, this);*/ g.setFont(font); g.setColor(Color.BLACK); g.clearRect(10, 440, 90, 50); g.drawString("Basket : " + Integer.toString(basketScore / 24), 10, 440); g.drawString("Ballons: " + Integer.toString(ballonScore), 10, 470); } else if (state == GameState.Dead) { g.setColor(Color.BLACK); g.fillRect(0, 0, 800, 480); g.setColor(Color.WHITE); g.drawString("Dead", 360, 240); } }
private Boolean existsCellOnTheSouth(Robot robot, CellState cell) { int robotDiamterInCellNum = robot.getDiameterInCellNum(); int rowID = robot.getSouthWestBlock().getRowID() + 1; for (int colOffset = 0; colOffset < robotDiamterInCellNum; colOffset++) { int colID = robot.getSouthWestBlock().getColID() + colOffset; if (this.exploredMap.getCell(rowID, colID) == cell) return true; } return false; }
public Robot moveTo(Robot robot, int x, int y) { if (isValidMove(x, y)) { robot.setX(x); robot.setY(y); } return robot; }
public void destroy(Widget w) { int id; if (!rwidgets.containsKey(w)) id = -1; else id = rwidgets.get(w); synchronized (robots) { for (Robot r : robots) r.dstwdg(id, w); } super.destroy(w); }
@Test public void test_example_c() { robot.place(1, 2, DirectionKind.EAST); robot.move(); robot.move(); robot.left(); robot.move(); org.junit.Assert.assertEquals("3,3,NORTH", robot.report()); }
public void checkVerticalCollision(Rectangle rtop, Rectangle rbot) { if (rtop.intersects(r)) {} if (rbot.intersects(r) && type == 8) { robot.setJumped(false); robot.setSpeedY(0); robot.setCenterY(tileY - 63); } }
public static void main(String[] asd) { Human human1 = new Human("Bob"); Human human2 = new Human("Chris"); Robot robot1 = new Robot("Greg", false); Robot robot2 = new Robot("Jim", false); Robot robot3 = new Robot("Jeff", false); Robot robot4 = new Robot("DarthVader", true); robot4.destroy(human1); robot3.destroy(human2); }
public MouseController() throws AWTException { // auto delay after each events robot.setAutoDelay(40); robot.setAutoWaitForIdle(true); robot.delay(5000); this.drawSomething(); this.drawCercle(new Point(846, 467), new Point(992, 603)); this.drawCercle(new Point(100, 100), new Point(300, 300)); this.drawCercle(new Point(500, 500), new Point(900, 200)); }
/** * Performs a drag action at the given location. * * @param target the target AWT or Swing {@code Component}. * @param where the point where to start the drag action. */ @RunsInEDT public void drag(@Nonnull Component target, @Nonnull Point where) { robot.pressMouse(target, where, LEFT_BUTTON); int dragDelay = settings().dragDelay(); if (dragDelay > delayBetweenEvents()) { pause(dragDelay); } mouseMove(target, where.x, where.y); robot.waitForIdle(); }