我是从C++转过来的,对于Swing控件的生存期有点疑问,请大家帮忙解释一下,看下面一段例子:class JButtonFrame extends JFrame
{
public JButtonFrame()
{
setTitle("ButtonTest");
setSize(DEFAULT_WIDTH,DEFAULT_HEIGTH);

JButton yellowButton = new JButton("Yellow");
JButton blueButton = new JButton("Blue");
JButton redButton = new JButton("Red");

m_buttonPanel = new JPanel();

m_buttonPanel.add(yellowButton);
m_buttonPanel.add(blueButton);
m_buttonPanel.add(redButton);

add(m_buttonPanel);

yellowAction = new ColorAction(Color.YELLOW);
blueAction = new ColorAction(Color.BLUE);
redAction = new ColorAction(Color.RED);

yellowButton.addActionListener(m_yellowAction);
blueButton.addActionListener(m_blueAction);
redButton.addActionListener(m_redAction);
}
……
yellowButton、blueButton、redButton都是临时new出来的对象,在这个构造函数的生存期结束的时候应该没有了?除非将其视为对象指针来看,m_buttonPanel保存了这些对象指针方才有效,但是按照C++的习惯来说,我还是喜欢将这三个button做成三个成员变量来使用,请问:我对于m_buttonPanel的理解是否正确呢?