简体   繁体   中英

how to disjoin child from jfram

please note to this:

public class test extended Jframe implement actionlistener{
test()
{

     Jpanel panel = new Jpqnel;
     Jbutton b = new Jbutton("1");
     b.addactionlistener(this);
     panel.add(b);
     add(panel);
 }
  public void actionPerformed(ActionEvent e) {


}

I want when i click on b button the child that add to Jframe(in this example: panel )

disjoint from it.

how can i do that?

By disjoin, if you mean remove, try

public class test extends JFrame implements ActionListener {
    JPanel panel;

    test() {

        panel = new JPanel();
        JButton b = new JButton("1");
        b.addActionListener(this);
        panel.add(b);
        add(panel);
        setVisible(true);
    }

    public void actionPerformed(ActionEvent e) {
        this.remove(panel);
        repaint();
    }

    public static void main(String a[]) {
        new test();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM