java setlocation_Java Point.setLocation方法代碼示例

本文整理匯總了Java中java.awt.Point.setLocation方法的典型用法代碼示例。如果您正苦於以下問題:Java Point.setLocation方法的具體用法?Java Point.setLocation怎麽用?Java Point.setLocation使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.Point的用法示例。

在下文中一共展示了Point.setLocation方法的20個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: computeTextLocation

​點讚 3

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;

}

開發者ID:buni-rock,項目名稱:Pixie,代碼行數:31,

示例2: Roundabout

​點讚 3

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");

}

開發者ID:JaneClelandHuang,項目名稱:Dronology,代碼行數:22,

示例3: dropFood

​點讚 3

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());

}

}

}

開發者ID:gamefest2017,項目名稱:ants,代碼行數:26,

示例4: print

​點讚 3

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));

}

}

}

開發者ID:Valkryst,項目名稱:VTerminal,代碼行數:37,

示例5: originalToResized

​點讚 2

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;

}

開發者ID:buni-rock,項目名稱:Pixie,代碼行數:17,

示例6: finish

​點讚 2

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);

}

}

}

開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,

示例7: layoutCirculary

​點讚 2

import java.awt.Point; //導入方法依賴的package包/類

private void layoutCirculary(Collection> nodes, GraphNode 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> 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;

}

}

}

開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:36,

示例8: relayoutNonFixed

​點讚 2

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;

}

}

}

開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:29,

示例9: actionPerformed

​點讚 2

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());

}

開發者ID:HY-ZhengWei,項目名稱:hy.common.ui,代碼行數:10,

示例10: setLocationForTable

​點讚 2

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());

}

}

開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:13,

示例11: getPopOverPosition

​點讚 2

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;

}

開發者ID:michaelnetter,項目名稱:dracoon-dropzone,代碼行數:41,

示例12: move

​點讚 2

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;

}

開發者ID:gamefest2017,項目名稱:ants,代碼行數:39,

示例13: getComponentCenterLocation

​點讚 2

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;

}

開發者ID:Axway,項目名稱:ats-framework,代碼行數:15,

示例14: findClosestTwoIndices

​點讚 2

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;

}

開發者ID:SensorsINI,項目名稱:jaer,代碼行數:44,

示例15: recursiveFill

​點讚 2

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 recursiveFill(final List 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;

}

開發者ID:Valkryst,項目名稱:VTerminal,代碼行數:43,

示例16: print

​點讚 2

import java.awt.Point; //導入方法依賴的package包/類

/**

* Prints a rectangle on a screen.

*

* If the function is set to perform connections, then it will attempt to

* connect the new rectangle with existing similar rectangles in the draw area.

*

* @param screen

* The screen.

*

* @param position

* The x/y-axis (column/row) coordinates of the top-left character.

*

* @throws NullPointerException

* If the screen is null.

*/

public void print(final @NonNull Screen screen, final Point position) {

final int width = dimensions.width;

final int height = dimensions.height;

final int x = position.x;

final int y = position.y;

final int lastRow = y + height - 1;

final int lastColumn = x + width - 1;

final Point writePosition = new Point(0, 0);

// Draw Corners:

screen.write(rectangleType.getTopLeft(), position);

writePosition.setLocation(lastColumn, y);

screen.write(rectangleType.getTopRight(), writePosition);

writePosition.setLocation(x, lastRow);

screen.write(rectangleType.getBottomLeft(), writePosition);

writePosition.setLocation(lastColumn, lastRow);

screen.write(rectangleType.getBottomRight(), writePosition);

// Draw Left/Right Sides:

for (int i = 1 ; i < height - 1 ; i++) {

writePosition.setLocation(x, y + i);

screen.write(rectangleType.getVertical(), writePosition);

writePosition.setLocation(lastColumn, y + i);

screen.write(rectangleType.getVertical(), writePosition);

}

// Draw Top/Bottom Sides:

for (int i = 1 ; i < width - 1 ; i++) {

writePosition.setLocation(x + i, y);

screen.write(rectangleType.getHorizontal(), writePosition);

writePosition.setLocation(x + i, lastRow);

screen.write(rectangleType.getHorizontal(), writePosition);

}

// Draw title on Top Side:

if (title != null && title.isEmpty() == false) {

// Draw Title Text:

final char[] titleChars = title.toCharArray();

for (int i = 2; i < width - 2 && i - 2 < titleChars.length; i++) {

writePosition.setLocation(x + i, y);

screen.write(titleChars[i - 2], writePosition);

}

// Draw Title Borders:

writePosition.setLocation(x + 1, y);

screen.write(rectangleType.getConnectorLeft(), writePosition);

writePosition.setLocation(x + titleChars.length + 2, y);

screen.write(rectangleType.getConnectorRight(), writePosition);

}

// Handle Connectors:

setConnectors(screen, position);

}

開發者ID:Valkryst,項目名稱:VTerminal,代碼行數:78,

示例17: nextPosition

​點讚 2

import java.awt.Point; //導入方法依賴的package包/類

protected void nextPosition(Point currentPos, Rectangle currentBounds, Point nextPos, Rectangle nextBounds, int dx, int dy) {

int x = currentPos.x + currentBounds.width + dx;

int y = currentPos.y;

nextBounds.setLocation(x, y);

nextPos.setLocation(x, y);

}

開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:7,

示例18: hasValidLeftNeighbour

​點讚 1

import java.awt.Point; //導入方法依賴的package包/類

/**

* Determines if the left-neighbour of a cell is both of the correct

* RectangleType and that the character of the left-neighbour can be

* connected to.

*

* @param position

* The x/y-axis (column/row) coordinates of the cell.

*

* @return

* If the left-neighbour is valid.

*

* @throws NullPointerException

* If the screen is null.

*/

private boolean hasValidLeftNeighbour(final @NonNull Screen screen, final Point position) {

try {

position.setLocation(position.x - 1, position.y);

return rectangleType.isValidLeftCharacter(screen.getCharacterAt(position));

} catch (final IllegalArgumentException e) {

return false;

}

}

開發者ID:Valkryst,項目名稱:VTerminal,代碼行數:23,

示例19: printFilled

​點讚 1

import java.awt.Point; //導入方法依賴的package包/類

/**

* Prints a rectangle on a screen.

*

* If the function is set to perform connections, then it will attempt to

* connect the new rectangle with existing similar rectangles in the draw area.

*

* @param screen

* The screen.

*

* @param position

* The x/y-axis (column/row) coordinates of the top-left character.

*

* @throws NullPointerException

* If the screen is null.

*/

public void printFilled(final @NonNull Screen screen, final Point position) {

print(screen, position);

final Dimension dimension = new Dimension(this.dimensions.width - 2, this.dimensions.height - 2);

position.setLocation(position.x + 1, position.y + 1);

for (final Point point : ShapeAlgorithms.getFilledRectangle(position, dimension)) {

screen.write(fillChar, point);

}

}

開發者ID:Valkryst,項目名稱:VTerminal,代碼行數:26,

示例20: getFilledEllipse

​點讚 1

import java.awt.Point; //導入方法依賴的package包/類

/**

* Constructs a list, containing the outline and fill, of an ellipse's points.

*

* @param position

* The x/y-axis (column/row) coordinates of the top-left character.

*

* @param dimension

* The width/height.

*

* @return

* The list of points.

*/

public static List getFilledEllipse(final Point position, final Dimension dimension) {

final List points = getEllipse(position, dimension);

final int xCenter = position.x + (dimension.width / 2);

final int yCenter = position.y + (dimension.height / 2);

position.setLocation(xCenter, yCenter);

return recursiveFill(points, position);

}

開發者ID:Valkryst,項目名稱:VTerminal,代碼行數:22,

注:本文中的java.awt.Point.setLocation方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值