本文整理汇总了Java中java.awt.Point.setLocation方法的典型用法代码示例。如果您正苦于以下问题:Java Point.setLocation方法的具体用法?Java Point.setLocation怎么用?Java Point.setLocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Point
的用法示例。
在下文中一共展示了Point.setLocation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeTextLocation
import java.awt.Point; //导入方法依赖的package包/类
/**
* Compute the position where a box with text shall be displayed, in such
* way that it will not go out of the image.
*
* @param box the initial position of the box
* @param labelSize the size of the text box
* @param bounds the bounds where the text should fit
* @return the position where the box shall be drawn, in order to avoid getting out of the bounds.
*/
public static Point computeTextLocation(Rectangle box, Dimension labelSize, Dimension bounds) {
Point pos = new Point(box.x, box.y - labelSize.height - 1);
if (pos.x < 0) {
pos.setLocation(0, pos.y);
}
if (pos.y < 0) {
pos.setLocation(pos.x, 0);
}
if ((box.x + labelSize.width) >= bounds.width) {
pos.setLocation(bounds.width - labelSize.width - 1, pos.y);
}
if ((box.y + labelSize.height) >= bounds.height) {
pos.setLocation(pos.x, bounds.height - labelSize.height - 1);
}
return pos;
}
示例2: Roundabout
import java.awt.Point; //导入方法依赖的package包/类
/**
* Constructs a roundabout to prevent collision of two drones. Creates a circle with 32 points on it.
* Drones travel clockwise and enter and exit at points only.
* @param drone Drone 1
* @param drone2 Drone 2
*/
public Roundabout(ManagedDrone drone, ManagedDrone drone2){ //Coordinates D1, Coordinates D2){
drone1Coords = drone.getCoordinates();
drone2Coords = drone2.getCoordinates();
//System.out.println(drone1Coords.toString() + " " + drone2Coords.toString());
hub = new Coordinates(0,0,0);
radius = 2000;
circumferenceCoordinates = new Coordinates[32];
constructRoundabout();
Point pnt = new Point();
pnt.setLocation(hub.getLatitude(),hub.getLongitude());
computeCirclePoints(32,radius,pnt);
computeDroneEntryExitPoints(drone);
computeDroneEntryExitPoints(drone2);
System.out.println("Roundabout built");
}
示例3: dropFood
import java.awt.Point; //导入方法依赖的package包/类
public void dropFood(final int turn) {
if (turn % FOOD_REFILL_FREQUENCY == 0) {
int row;
int column;
final Point position = new Point(0, 0);
do {
row = RANDOMIZER.nextInt(X_BOUNDRY / 2);
if (turn % (FOOD_REFILL_FREQUENCY * 2) == 0) {
row += X_BOUNDRY / 2;
}
column = RANDOMIZER.nextInt(Y_BOUNDRY - 1);
position.setLocation(row, column);
System.out.println("Generated food x-position : " + row);
} while (this.world.isPositionOccupied(position) || this.world.isHillPosition(position));
final Food newFood = new Food(this.world.idSequence++, 1, position);
try {
this.world.placeObject(newFood);
} catch (final InvalidWorldPositionException e) {
System.out.println(
"Position had not space, food was not dropped. Position was: " + newFood.getPosition());
}
}
}
示例4: print
import java.awt.Point; //导入方法依赖的package包/类
/**
* Prints an image on a component.
*
* @param component
* The component.
*
* @param columnIndex
* The x-axis (column) coordinate of the top-left character.
*
* @param rowIndex
* The y-axis (row) coordinate of the top-left character.
*
* @throws NullPointerException
* If the screen is null.
*/
private void print(final @NonNull Component component, final int columnIndex, final int rowIndex) {
final BufferedImage temp = applyTransformations();
final Point charPosition = new Point(0, 0);
for (int y = 0 ; y < temp.getHeight() && y < component.getHeight() ; y++) {
for (int x = 0 ; x < temp.getWidth() && x < component.getWidth() ; x++) {
final int hexColor = temp.getRGB(x,y);
final int red = (hexColor & 0x00ff0000) >> 16;
final int green = (hexColor & 0x0000ff00) >> 8;
final int blue = hexColor & 0x000000ff;
final int charX = x + columnIndex;
final int charY = y + rowIndex;
charPosition.setLocation(charX, charY);
final AsciiCharacter character = component.getCharacterAt(charPosition);
character.setCharacter(printChar);
character.setForegroundColor(new Color(red, green, blue));
}
}
}
示例5: originalToResized
import java.awt.Point; //导入方法依赖的package包/类
/**
* Computes the corespondent position in the resized image, of the given
* pixel from the original image.
*
* @param origPoint - the (x,y) coordinate of the pixel from the original image
* @return - returns a Point object with two elements: x and y coordinates of the point in the resized image (in this order)
*/
public Point originalToResized(Point origPoint) {
if ((origPoint == null) || (Double.compare(ratioWidth, 0.0) == 0) || (Double.compare(ratioHeight, 0.0) == 0)) {
return null;
}
Point resizedPoint = new Point();
resizedPoint.setLocation((int) (origPoint.getX() / ratioWidth), (int) (origPoint.getY() / ratioHeight));
return resizedPoint;
}
示例6: finish
import java.awt.Point; //导入方法依赖的package包/类
private void finish() {
for (GraphNode n : scene.getNodes()) {
NodeWidget w = getWidget(n);
Widget wid = scene.findWidget(n);
Point point = new Point();
point.setLocation(w.locX, w.locY);
if (scene.isAnimated()) {
scene.getSceneAnimator().animatePreferredLocation(wid, point);
} else {
wid.setPreferredLocation(point);
}
}
}
示例7: layoutCirculary
import java.awt.Point; //导入方法依赖的package包/类
private void layoutCirculary(Collection<GraphNode<I>> nodes, GraphNode<I> masterNode) {
Point masterPoint = new Point();
NodeWidget master = getWidget(masterNode);
masterPoint.setLocation(master.locX, master.locY);
double r;
double theta;
double thetaStep = Math.PI / 5;
r = 150;
theta = 0;
Iterator<GraphNode<I>> it = nodes.iterator();
NodeWidget nw = getWidget(it.next());
while (true) {
AffineTransform tr = AffineTransform.getRotateInstance(theta);
Point2D d2point = tr.transform(new Point2D.Double(0, r), null);
Point point = new Point((int)d2point.getX() + masterPoint.x, (int)d2point.getY() + masterPoint.y);
if (isThereFreeSpace(point, nw)) {
nw.locX = point.getX();
nw.locY = point.getY();
nw.dispX = 0;
nw.dispY = 0;
if (it.hasNext()) {
nw = getWidget(it.next());
} else {
return;
}
}
theta = theta + thetaStep;
if (theta > (Math.PI * 2 - Math.PI / 10)) {
r = r + 90;
theta = theta - Math.PI * 2;
thetaStep = thetaStep * 3 / 4;
}
}
}
示例8: relayoutNonFixed
import java.awt.Point; //导入方法依赖的package包/类
private void relayoutNonFixed(NodeWidget w) {
Point masterPoint = new Point();
masterPoint.setLocation(w.locX, w.locY);
double r;
double theta;
double thetaStep = Math.PI / 5;
r = 30;
theta = 0;
w.setFixed(false);
while (true) {
AffineTransform tr = AffineTransform.getRotateInstance(theta);
Point2D d2point = tr.transform(new Point2D.Double(0, r), null);
Point point = new Point((int)d2point.getX() + masterPoint.x, (int)d2point.getY() + masterPoint.y);
w.locX = point.getX();
w.locY = point.getY();
if (isThereFreeSpaceNonFixedSpace(w)) {
w.setFixed(true);
return;
}
theta = theta + thetaStep;
if (theta > (Math.PI * 2 - Math.PI / 10)) {
r = r + 30;
theta = theta - Math.PI * 2;
thetaStep = thetaStep * 3 / 4;
}
}
}
示例9: actionPerformed
import java.awt.Point; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent e)
{
Point v_Point = this.button.getLocationOnScreen();
v_Point.setLocation(v_Point.getX() ,v_Point.getY() + this.button.getHeight());
this.jdt.setLocation(v_Point);
this.jdt.setVisible(!this.jdt.isVisible());
}
示例10: setLocationForTable
import java.awt.Point; //导入方法依赖的package包/类
/**
* Sets the location to a point the table.
*
* @param table
* @param location
*/
private void setLocationForTable(JTable table, Point location) {
if (location != null) {
Rectangle cellRect = table.getCellRect(table.getEditingRow(), table.getEditingColumn(), false);
location.setLocation(cellRect.getLocation());
}
}
示例11: getPopOverPosition
import java.awt.Point; //导入方法依赖的package包/类
/**
* Returns the position of the upper left corner of the popover winndow
*
* @param pos
* @return
*/
public static Point getPopOverPosition() {
ConfigIO cfg = ConfigIO.getInstance();
String screenId = cfg.getScreenId();
ScreenModel screenModel = getScreen(screenId);
int screenWidth = screenModel.getWidth();
int screenHeight = screenModel.getHeight();
Point point = screenModel.getTopLeftCorner();
int scrPosId = cfg.getScreenPositionId();
ScreenPosition screenPos = getScreenPosition(scrPosId);
Pos pos = screenPos.getPos();
switch (pos) {
case TOP_LEFT:
point.setLocation(point.x + PADDING, point.y + 0 + ARROW_SIZE);
break;
case TOP_RIGHT:
point.setLocation(point.x + screenWidth + PADDING / 2, point.y + 0 + ARROW_SIZE);
break;
case BOTTOM_LEFT:
point.setLocation(point.x + PADDING, point.y + screenHeight + DropzonePopOver.HEIGHT - ARROW_SIZE * 2);
break;
case BOTTOM_RIGHT:
point.setLocation(point.x + screenWidth + PADDING / 2,
point.y + screenHeight + DropzonePopOver.HEIGHT - ARROW_SIZE * 2);
break;
}
return point;
}
示例12: move
import java.awt.Point; //导入方法依赖的package包/类
public IAnt move(final IAnt ant, final Direction direction) throws MoveException {
final double newXPos = ant.getPosition().getX() + direction.getPositionChange().getX();
final double newYPos = ant.getPosition().getY() + direction.getPositionChange().getY();
final Point destination = new Point((int) newXPos, (int) newYPos);
if (this.world.isPositionOccupiedByBorder(destination)) {
throw new MoveException("Can't go to border of the world grid at position " + destination);
}
final Point position = new Point();
position.setLocation(newXPos, newYPos);
if (ant instanceof AbstractAnt && ant.getMyHill().getPosition().equals(position)) {
moveHome(ant.getMyHill(), (AbstractAnt) ant);
}
final Object worldObject = this.world.getWorldObject(position);
if (worldObject == null || ant.getMyHill().getPosition().equals(position)) {
System.out.println("I'm moving from [" + ant.getPosition().x + ", " + ant.getPosition().y + "] to "
+ direction.name() + "[" + position.x + ", " + position.y + "]" + ", out of my way!");
ant.setPosition(position);
} else if (worldObject instanceof Food && ant instanceof AbstractAnt) {
final AbstractAnt worker = (AbstractAnt) ant;
final Food food = (Food) worldObject;
if (!worker.hasFood()) {
worker.pickUpFood(food);
this.world.removeObject(food);
}
worker.setPosition(position);
} else if (worldObject instanceof IAnt && ant instanceof AbstractWarrior && ant.isEnemy((IAnt) worldObject)) {
final AbstractWarrior warrior = (AbstractWarrior) ant;
moveToEnemyAndKill(warrior, (IAnt) worldObject);
warrior.setPosition(position);
} else {
System.out.println("I will not move to " + direction.name() + "! The place is occupied.");
}
return ant;
}
示例13: getComponentCenterLocation
import java.awt.Point; //导入方法依赖的package包/类
/**
* Get the component center location {@link Point}
*
* @param component the target component
* @return center location {@link Point}
*/
private Point getComponentCenterLocation(
Component component ) {
Point centerPoint = new Point();
centerPoint.setLocation(component.getX() + component.getWidth() / 2,
component.getY() + component.getHeight() / 2);
return centerPoint;
}
示例14: findClosestTwoIndices
import java.awt.Point; //导入方法依赖的package包/类
/**
* Finds the nearest two track points to a Point2D double point. This method
* uses the fast local minimum search to find the nearest point, then checks
* in each direction for the next nearest point.
*
* @param p the Point2D in x,y space.
* @return a Point with the two nearest track points as x (nearest) and y
* (next nearest).
*/
public Point findClosestTwoIndices(Point2D p) {
Point idxP = new Point(-1, -1);
if (trackPoints == null) {
return idxP;
}
int idx1 = findClosestIndex(p, Float.MAX_VALUE, true); // true=fast search, starting where last one ended.
if (idx1 >= 0) {
// Find which one of the neighbors is closest
int idx2 = idx1 - 1;
if (idx2 < 0) {
idx2 = getNumPoints() - 1;
}
int idx3 = idx1 + 1;
if (idx3 >= getNumPoints()) {
idx3 = 0;
}
Point2D p2 = getPoint(idx2);
Point2D p3 = getPoint(idx3);
double dist2 = p2.distance(p);
double dist3 = p3.distance(p);
if (dist2 < dist3) {
idxP.setLocation(max(idx1, idx2), min(idx1, idx2));
} else {
idxP.setLocation(max(idx1, idx3), min(idx1, idx3));
}
}
return idxP;
}
示例15: recursiveFill
import java.awt.Point; //导入方法依赖的package包/类
/**
* Recursively fills an area on the screen bounded by the set of input points.
*
* @param points
* The border points.
*
* @param position
* The x/y-axis (column/row) coordinates of the current point.
*
* @return
* The list of filled points.
*/
public static List<Point> recursiveFill(final List<Point> points, final Point position) {
boolean pointExists = false;
int x = position.x;
int y = position.y;
for (final Point point : points) {
if (point.x == x && point.y == y) {
pointExists = true;
break;
}
}
if (pointExists == false) {
points.add(new Point(x, y));
position.setLocation(x + 1, y);
recursiveFill(points, position);
position.setLocation(x - 1, y);
recursiveFill(points, position);
position.setLocation(x, y + 1);
recursiveFill(points, position);
position.setLocation(x, y - 1);
recursiveFill(points, position);
}
return points;
}