这段代码有问题,我找不出来,麻烦各位高手帮帮忙class ButtonPanel extends JPanel{
//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 action
ColorAction yellowAction = new ColorAction(Color.YELLOW);
ColorAction buleAction = new ColorAction(Color.BLUE);
ColorAction redAction = new ColorAction(Color.RED);
//associate actions with buttons
yellowButton.addActionListener(yellowAction);
blueButton.addActionListener(buleAction);
redAction.addActionListener(redAction);
//An action listener that sets implements ActionListener
private class ColorAction implements ActionListener{
private Color backgroundColor;
public ColorAction(Color c){
backgroundColor = c;
}
public void actionPerformed(ActionEvent event){
setBackground(backgroundColor);
}
}
}
class前面没有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 action
ColorAction yellowAction = new ColorAction(Color.YELLOW);
ColorAction buleAction = new ColorAction(Color.BLUE);
ColorAction redAction = new ColorAction(Color.RED);
//associate actions with buttons
yellowButton.addActionListener(yellowAction);
blueButton.addActionListener(buleAction);
redAction.addActionListener(redAction);
//An action listener that sets implements ActionListener
private class ColorAction implements ActionListener{
private Color backgroundColor;
public ColorAction(Color c){
backgroundColor = c;
}
public void actionPerformed(ActionEvent event){
setBackground(backgroundColor);
}
}
}
class前面没有public是ButtonPanel因为是内部类
解决方案 »
- 关于类的封装问题
- 正则表达式问题
- 请问学习java线程有什么用啊,实际开发什么内容时会用到,还有很多人开发说jbuilder不好,吃内存,那么用eclipes,jcreate写按钮什么的还
- 变量的定义问题!
- **************Question******************Help me!!!!!!!!!!
- JTree类显示文件目录树的问题
- 如何通过一个函数改变传入的一个参数的值(参数类型如String int)???????
- vj中如何连接sqlserver???(直连接不是jdbc-odbc)
- 请问如何在一个java类里调用生成另外一个java类的批处理文件?
- 请问如何将嵌在JTabbedPane上的JTable能冲满整个Panel?代码如下:
- 怎么设置文本域不能修改?
- 关于Applet和JApplet的刷新问题
JButton yellowButton = new JButton("Yellow");
JButton blueButton = new JButton("Blue");
JButton redButton = new JButton("Red");
ColorAction yellowAction = new ColorAction(Color.YELLOW);
ColorAction buleAction = new ColorAction(Color.BLUE);
ColorAction redAction = new ColorAction(Color.RED); public ButtonPanel() {
add(yellowButton);
add(blueButton);
add(redButton);
yellowButton.addActionListener(yellowAction);
blueButton.addActionListener(buleAction);
redButton.addActionListener(redAction);
} private class ColorAction implements ActionListener {
private Color backgroundColor; public ColorAction(Color c) {
backgroundColor = c;
} public void actionPerformed(ActionEvent e) {
setBackground(backgroundColor);
}
}
}