gpt4 book ai didi

java - 如何使用户放置的元素可点击?

转载 作者:行者123 更新时间:2023-11-30 09:36:31 26 4
gpt4 key购买 nike

<分区>

我有一个程序,一个人可以在屏幕上放置一个代表 warpgate 的元素。我想知道之后如何找到元素的位置,以便程序可以捕获该区域中的点击。

这是我目前拥有的:

int xCoord22[];
int yCoord22[];
int numSquare22;

int warpGate = 0;

public void init()
{

warpgate = getImage(getDocumentBase(),"image/warpgate.png");

xCoord22 = new int[100];
yCoord22 = new int[100];
numSquare22 = 0;
}

public void paint(Graphics g)
{

warpGate(g);
}

public void warpGate(Graphics g)
{
//Checks if warpgate == 1 then will make the warp gate where the user chooses
if(warpGate == 1)
{

g.drawImage(warpgate,510,820,100,100,this);
//Use the custom cursor
setCursor(cursor2);

}

//Building the pylons
if(Minerals >= 150)
{

for (int k = 0; k < numSquare22; k++)
{

g.drawImage(warpgate,xCoord22[k],yCoord22[k],120,120,this);
//Makes cursor normal.
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
}
}

public boolean mouseDown(Event e, int x, int y)
{
if(warpGate == 1)
{
if(Minerals >= 150)
{
xCoord22[numSquare22] = x;
yCoord22[numSquare22] = y;
numSquare22++;
handleWarpGatePlacement();
repaint();
}
}

//Checks to see if the person clicks on the warpGate icon so you can build it
if(x > 1123 && x < 1175 && y > 782 && y < 826 && onNexus == 1 && Minerals >= 250)
{
warpGate = 1;

}

所以,基本上,当您单击 x > 1123 && x < 1175 && y > 782 && y < 826 时你可以放置一个传送门。我怎样才能做到这样你以后把它放在哪里你只需点击它它就会像system.out.print("hey");一样还是别的?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com