JLabel的控制

发布于 2024-10-10 04:32:14 字数 158 浏览 0 评论 0原文

我使用 GUI 构建器在 JFrame 中构建了一组 JLabels 和 4 个箭头。我希望当我按下其中一个箭头时能够对相应的标签执行操作。即,当控件位于第一个标签上时,“右”箭头会将控件“带到”右侧标签上。我还想提一下,由于 GUI 构建器,我无法(??)使用数组并增加/减少指针。有什么想法吗?:)

I have built, with a GUI builder, a set of JLabels and 4 arrows in a JFrame. I want, when I press one of the arrows to be able to perform operations on the correspondent label. I.e when the control is on the first label the "right" arrow would "bring" the control on the right label. I also want to mention that due to GUI builder I can't(??) use array and increase/decrease the pointers. Any ideas?:)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伤感在游骋 2024-10-17 04:32:14

听起来您试图将 GUI 与数据配对得太紧密。当有人单击按钮时,它应该对您的数据执行一些操作。该操作完成后,GUI 应更新以反映新数据。这比在窗口内移动控件要容易得多。这称为模型视图控制器模式

It sounds like you are trying to pair your GUI too closely to your data. When someone clicks on a button, it should perform some action on your data. Once that action is complete, the GUI should be updated to reflect the new data. This is much easier than moving controls within the window. This is known as the Model View Controller pattern.

泼猴你往哪里跑 2024-10-17 04:32:14

阅读 Swing 教程中有关如何使用键绑定的部分。一般来说,这允许您定义一个在调用 KeyStroke 时执行的操作。因此,您可以为每个右/左/上/下箭头键设置不同的操作。

Read the section from the Swing tutorial on How to Use Key Bindings. In general, this allows you to define an Action that is executed when a KeyStroke is invoked. So you can have a different Action for each of the right/left/up/down arrow keys.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文