繁体   English   中英

如何使JButton更改JLabel中文本的位置

[英]how to make JButton changes the location of the text inside JLabel

如何设置按下JPanel时更改JLabel上JLabel位置的JButton? 如何在JButton上为此实现actionlistener?

您想先将动作监听器添加到按钮

button.addActionListener(new ButtonListener());

接下来,您要创建自定义类

class ButtonListener implements ActionListener {
     public void actionPerformed(ActionEvent e) {
            if(e.getSource() == button) {
                 label.setLocation(xValue, yValue);
            }
     }
}

将xValue / yValue更改为您希望标签更改为的x和y值。

我希望这有帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM