![](/img/trans.png)
[英]How do I make text inside a Jbutton into a variable that updates after it changes?
[英]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.