请注意:
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) {
}
我想点击b
按钮添加到Jframe的子项(在此示例中为panel
)
脱节。
我该怎么做?
答案 0 :(得分:0)
如果您要删除,请尝试删除,请尝试
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();
}
}