F
feiren
Unregistered / Unconfirmed
GUEST, unregistred user!
class ButtonPanel extends JPanel
{
public ButtonPanel()
{
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
ColorAction yellowAction = new ColorAction(Color.yellow);
ColorAction blueAction = new ColorAction(Color.blue);
ColorAction redAction = new ColorAction(Color.red);
//associate actions with buttons
yellowButton.addActionListener(yellowAction);
blueButton.addActionListener(blueAction);
redButton.addActionListener(redAction);
}
private class ColorAction implements ActionListener
{
public ColorAction(Color c)
{
backgroundColor=c;
}
public void actionPerformed(ActionEvent event)
{
setBackground(backgroundColor);
repaint();
}
private Color backgroundColor;
}
}
错误提示:ActionEventDemo.java:62: ButtonPanel.ColorAction is not abstract anddo
es not override abstract m
ethod actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
private class ColorAction implements ActionListener
1 error
{
public ButtonPanel()
{
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
ColorAction yellowAction = new ColorAction(Color.yellow);
ColorAction blueAction = new ColorAction(Color.blue);
ColorAction redAction = new ColorAction(Color.red);
//associate actions with buttons
yellowButton.addActionListener(yellowAction);
blueButton.addActionListener(blueAction);
redButton.addActionListener(redAction);
}
private class ColorAction implements ActionListener
{
public ColorAction(Color c)
{
backgroundColor=c;
}
public void actionPerformed(ActionEvent event)
{
setBackground(backgroundColor);
repaint();
}
private Color backgroundColor;
}
}
错误提示:ActionEventDemo.java:62: ButtonPanel.ColorAction is not abstract anddo
es not override abstract m
ethod actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
private class ColorAction implements ActionListener
1 error