gpt4 book ai didi

java - 多个 Jpanel 按键监听器空间

转载 作者:行者123 更新时间:2023-11-30 04:24:49 24 4
gpt4 key购买 nike

我有一个包含 4 个不同面板的框架。一个面板包含一个音乐播放器,按 Space 键开始播放音乐,而其他 3 个面板包含文本字段和一些提交按钮。现在我的问题是在任何这些文本字段中输入文本时,它都会接受输入,但每当我尝试在这些文本字段中留出空间时,它都会播放音乐,而不是在文本字段中输入空格。

最佳答案

I have a frame which contains 4 different panels.One panels contains a music player which on pressing space key start playing the music while other 3 panels contains textfields and some submit buttons.Now my problem is that while typing text in any of those textfield it's taking the input but whenever i try to give space in those textfield it's playing that music instead of typing a space in the textfield.

the listener is attached only to the music panel and not to anything else

  • 将 KeyBindings 添加到 JFrame(包含 4 个 JPanel)

  • 输出应该是 Swing Action

  • 在 Swing 操作中覆盖 setEnabled

  • 将所有 JComponent(仅用于用户输入)添加到数组

  • 添加 FocusListener 或所有 JComponent(仅用于用户输入)

  • on focusGained 添加到数组的任何 a.m. JComponent 都应该更改

  • 但是如何重置 Swing Action 的 isEnabled(true),只能通过 Swing Timer

<小时/>

口水战

  • 对用户不友好,完全不可能,错误的想法,有很多副作用

  • 错了,错了,一切都错了,你无法确定任何可用作 JTextComponents、JSlider、JComboBox(自动完成)、带有 isCellEditable(true) 的 JTable 输入字符的 KeyShortCuts

  • SPACE 也用作 JButton(在 API 中实现的 KeyBindings)的加速器,等等...

<小时/>

使用 JToggleButton 代替 JPanel,

  • 有两种状态

  • 可以不修饰,然后看起来像 JPanel(例如)

  • 使用图标,放在那里播放(停止)图标,文本,用gif动画看几次

  • SPACE 是加速器(在 focusGained 上)

  • 也可以从 MouseEvents 访问

关于java - 多个 Jpanel 按键监听器空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16210814/

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