![](/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.