[求助]菜鸟的小白问题

wallflower 2005-03-27 08:08:31
以下是core java上的一个关于事件处理的小程序,敲上去以后有两个错误怎么也看不出来。。本人初学java,望诸位高手指点。。

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class ButtonPanel extends JPanel
{
public ButtonPanel()
{
JButton yellowButton=new JButton("Yellow");
JButton blueButton=new JButton("Blue");
JButton redButton=new JButton("Red");

add(yellowButton);
add(blueButton);
add(redButton);

ColorAction yellowAction=new ColorAction(Color.YELLOW);
ColorAction blueAction=new ColorAction(Color.BLUE);
ColorAction redAction=new ColorAction(Color.RED);
yellowButton.addActionListener(yellowAction);
blueButton.addActionListener(blueAction);
redButton.addActionListener(redAction);
}

private class ColorAction implements ActionListener
{
public ColorAction(Color c)
{
backgroundColor=c;
}
31 public void actionPerformed(ActionEvent event);
{
33 setBackground(backgroundColor);
}
private Color backgroundColor;
};
}

class ButtonFrame extends JFrame
{
public ButtonFrame()
{
setTitle("Button");
setLocation(WIDTH,HEIGHT);
setSize(WIDTH,HEIGHT);
ButtonPanel panel=new ButtonPanel();
Container pane=getContentPane();
pane.add(panel);
}

private final int WIDTH=300;
private final int HEIGHT=200;
}

public class MyMain
{
public static void main(String[] args)
{
ButtonFrame myFrame=new ButtonFrame();
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.show();
}
}

错误提示
31 missing method body,or declare abstract
33 illegal forward reference
...全文
99 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
topil 2005-03-28
  • 打赏
  • 举报
回复
呵呵。路过
wallflower 2005-03-27
  • 打赏
  • 举报
回复
吐血了。。都怪自己太粗心,多谢楼上!
milkbottle 2005-03-27
  • 打赏
  • 举报
回复
31 行最后多了一个分号

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧