在一个小程序中,我使用 button
。我们可以通过点击按钮 3 次来设置三个标签吗?
最佳答案
你的意思是这样吗?
int count = 0;
String[] texts = new String[] {"Text 1", "Text 2", "Text 3"};
yourButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
if(count < 3) yourLabel.setText(texts[count]);
count++;
}
});
关于java - 单击按钮时在 Java 中设置标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8201584/