当前位置: 技术问答>java相关
事件处理小问题~~~~~~~~在线等!!
来源: 互联网 发布时间:2015-10-13
本文导语: class ButtonPanel extends JPanel { public ButtonPanel() { // create buttons JButton yellowButton = new JButton("Yellow"); JButton blueButton = new JButton("Blue"); JButton redButton = new JButton("R...
class ButtonPanel extends JPanel
{
public ButtonPanel()
{
// create buttons
JButton yellowButton = new JButton("Yellow");
JButton blueButton = new JButton("Blue");
JButton redButton = new JButton("Red");
// add buttons to panel
add(yellowButton);
add(blueButton);
add(redButton);
// create button actions
1。 ColorAction yellowAction = new ColorAction(Color.YELLOW);
ColorAction blueAction = new ColorAction(Color.BLUE);
ColorAction redAction = new ColorAction(Color.RED);
// associate actions with buttons
2。 yellowButton.addActionListener(yellowAction);
blueButton.addActionListener(blueAction);
redButton.addActionListener(redAction);
}
/**
An action listener that sets the panel's background color.
*/
private class ColorAction implements ActionListener
{
3。 public ColorAction(Color c)
{
backgroundColor = c;
}
4。 public void actionPerformed(ActionEvent event)
{
setBackground(backgroundColor);
}
private Color backgroundColor;
}
}
请问一下,在我的标记处,执行的顺序是怎么样的?? ,并且yellowAction 等是怎样进入监听的??在此先谢了~~~~~~~~~~
{
public ButtonPanel()
{
// create buttons
JButton yellowButton = new JButton("Yellow");
JButton blueButton = new JButton("Blue");
JButton redButton = new JButton("Red");
// add buttons to panel
add(yellowButton);
add(blueButton);
add(redButton);
// create button actions
1。 ColorAction yellowAction = new ColorAction(Color.YELLOW);
ColorAction blueAction = new ColorAction(Color.BLUE);
ColorAction redAction = new ColorAction(Color.RED);
// associate actions with buttons
2。 yellowButton.addActionListener(yellowAction);
blueButton.addActionListener(blueAction);
redButton.addActionListener(redAction);
}
/**
An action listener that sets the panel's background color.
*/
private class ColorAction implements ActionListener
{
3。 public ColorAction(Color c)
{
backgroundColor = c;
}
4。 public void actionPerformed(ActionEvent event)
{
setBackground(backgroundColor);
}
private Color backgroundColor;
}
}
请问一下,在我的标记处,执行的顺序是怎么样的?? ,并且yellowAction 等是怎样进入监听的??在此先谢了~~~~~~~~~~
|
1..3..2..4
|
1324