-1

So i want to know how to make buttons disappear. I have something like this...

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

I also want it to make other buttons disappear how do i do that? I tried to do something like this...

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);
        }
    });
Filburt
  • 17,626
  • 12
  • 64
  • 115

1 Answers1

1

You may use next code:

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

Or, use lambda expression in Java 8, for example:

button1.addActionListener(e -> button1.setVisible(false));
Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142
  • So how do i make other buttons disappear? sorry but I'm new to this gui stuff – Hayden Ingram Jun 10 '15 at 19:34
  • `[your gui object name].setVisible(flag)`, where flag is a boolean value: `true` or `false`. Are you understand me? – Andrew Tobilko Jun 10 '15 at 19:35
  • so i know that it needs to be higher in the code but i don't know how to make it do both i have something like this... – Hayden Ingram Jun 10 '15 at 21:03
  • JButton button1 = new JButton("1"); button1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { button1.setVisible(false); button2.setVisible(false); } }); button1.setBounds(48, 36, 39, 23); JButton button2 = new JButton("2"); button2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { button2.setVisible(false); button1.setVisible(false); } }); button2.setBounds(97, 36, 38, 23); – Hayden Ingram Jun 10 '15 at 21:05
  • JButton button1 = new JButton("1"); button1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { button1.setVisible(false); button2.setVisible(false); } }); button1.setBounds(48, 36, 39, 23); JButton button2 = new JButton("2"); button2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { button2.setVisible(false); button1.setVisible(false); } }); button2.setBounds(97, 36, 38, 23); – Hayden Ingram Jun 11 '15 at 05:30
  • @HaydenIngram, What don't you understand here? – Andrew Tobilko Jun 11 '15 at 11:29