-1

所以我想知道如何让按钮消失。我有这样的东西...

JButton button1 = new JButton("1");
    button1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            (what goes here to make it disappear?)
        }
    });

我也希望它使其他按钮消失我该怎么做?我试图做这样的事情......

JButton button1 = new JButton("1");
    button1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            share.setOnClickListener(new OnClickListener(){
public void onClick(View v){
linearlayoutbar1.setVisibility(View.GONE);
        }
    });
4

1 回答 1

1

您可以使用下一个代码:

JButton button1 = new JButton("1");
button1.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        button1.setVisible(false);
    }
});

或者,在 Java 8 中使用 lambda 表达式,例如:

button1.addActionListener(e -> button1.setVisible(false));
于 2015-06-10T19:32:28.133 回答