如何让点击图片时出现JTextField?
所以我正在尝试制作这个程序,允许用户使用 java 来标记照片(有点像 Facebook 标记)。我已经加载了图像,并在用户单击图像的某个区域时制作了鼠标侦听器。
当用户单击照片的特定区域时,如何使 JTextField 出现?
我认为 JTextField 在某种程度上可以是用户可以输入他/她的名字作为照片标签的框。
另外,您认为我应该将 JTextField 代码放在哪里?主要?
So I'm trying to make this program that allows the user to tag photos using java (kinda like Facebook tagging). I have already done loading the image, and making mouselistener when the user clicks an area of the image.
How do I make a JTextField appear when the user clicks a certain area of the photo?
I'm thinking that the JTextField can somewhat be the box where the user can enter his/her name as a tag for the photo.
Also, where do you think I should put the JTextField code? In main?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以获得 X 和 Y 坐标(如 Daggeto 所说)。然后你可以使用 setVisible(true) 显示你的文本字段
You can get the X and Y co-ordinates (as said by Daggeto). And then you can show your text field with setVisible(true)
只需在 JTextField 对象上使用 setVisible() 函数,并在用户访问图像的某个部分时设置其值。
just use the setVisible() function on the JTextField object and set its value whenever the user a certain portion of the image.
MouseEvent.getX()
和MouseEvent.getY()
返回事件相对于源组件的水平 x 和垂直 y 位置。然后,如果您将图像区域描述为 x1,x2,y1,y2,您可以通过以下“if”检查该区域中的点击位置:
MouseEvent.getX()
andMouseEvent.getY()
returns the horizontal x ant vertical y position of the event relative to the source component.Then if you your image area described as x1,x2,y1,y2 you can check is clicked position in this area by this 'if':