单击按钮,在Java中设置标签

时间:2011-11-20 12:50:47

标签: java

在applet中我使用的是button。点击一个按钮可以设置三个标签吗?

1 个答案:

答案 0 :(得分:5)

你的意思是这样吗?

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++;
    }

});