我只是在搞乱 MouseListener 并想在buttP
单击时向我的面板添加一个新的 JButton;但是,当我按 时它不会刷新面板buttP
。我尝试了重绘方法,但这不起作用。任何人都知道我如何刷新面板以便JButton
自动显示新的?
public class Panel extends JPanel{
private JButton buttP;
public Panel(){
buttP = new JButton("TEST");
buttP.addMouseListener(new addNewButtMouseListener());
add(buttP);
}
private class addNewButtMouseListener implements MouseListener{
@Override
public void mouseClicked(MouseEvent e) {
JButton b = new JButton("HA");
add(b);
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
}
}
非常感谢