JAVA基础题希望各位朋友帮个忙

Ramy_1224 2007-10-06 06:15:18
package dome;
import javax.swing.*;
import java.awt.*;
import java.awt.Event;
public class Textpanel extends JPanel
{
public Textpanel()
{
JButton yellow=new JButton("yellow");
JButton blue=new JButton("blue");
JButton green=new JButton("green");
add(yellow);
add(blue);
add(green);
ColorAction yellowAction=new ColorAction(Color.yellow);
ColorAction blueAction=new ColorAction(Color.blue);
ColorAction greenAction=new ColorAction(Color.green);
yellow.addActionListener(yellowAction);
blue.addActionListener(blueAction);
green.addActionListener(greenAction);
}
private class ColorAction implements ActionListener
{
private Color temp;
public ColorAction(Color c)
{
temp=c;
}
public void actionPerformen(ActionEvent e)
{
setBackground(temp);
}
}

}
谁能告诉我 内部类的setBackground();是从哪里来的?
我实现ActionListener接口时候会报错这是为什么?
...全文
167 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
jefyjiang 2007-10-06
  • 打赏
  • 举报
回复
没有把ActionListener 这个类import进来
jefyjiang 2007-10-06
  • 打赏
  • 举报
回复
没有把ActionListener 这个类import进来
sszhangy 2007-10-06
  • 打赏
  • 举报
回复
把import java.awt.Event; 改为import java.awt.event.*;

ActionListener这个类在java.awt.event这个包里。

调试技巧需要多多练习才能进步,lz加油!
woaiguazi000 2007-10-06
  • 打赏
  • 举报
回复
这是基本上所有的setBackguoud()方法:setBackground(Color) - 类 java.awt.Component.AccessibleAWTComponent 中的方法
设置此对象的背景色。
setBackground(Color) - 类 java.awt.Component 中的方法
设置组件的背景色。
setBackground(Color) - 类 java.awt.Graphics2D 中的方法
设置 Graphics2D 上下文的背景色。
setBackground(Color) - 类 java.awt.List.AccessibleAWTList.AccessibleAWTListChild 中的方法
设置此对象的背景颜色。
setBackground(Color) - 类 java.awt.MenuComponent.AccessibleAWTMenuComponent 中的方法
设置此对象的背景色。
setBackground(Color) - 类 java.awt.TextComponent 中的方法
设置此文本组件的背景色。
setBackground(Color) - 接口 javax.accessibility.AccessibleComponent 中的方法
设置此对象的背景色。
setBackground(Color) - 类 javax.swing.JComponent 中的方法
设置此组件的背景色。
setBackground(Color) - 类 javax.swing.JList.AccessibleJList.AccessibleJListChild 中的方法

setBackground(Color) - 类 javax.swing.JTable.AccessibleJTable.AccessibleJTableCell 中的方法
设置此对象的背景色。
setBackground(Color) - 类 javax.swing.JTree.AccessibleJTree.AccessibleJTreeNode 中的方法
设置此对象的背景色。
setBackground(Color) - 类 javax.swing.table.DefaultTableCellRenderer 中的方法
重写 JComponent.setBackground 将未选定单元格的背景色分配为指定颜色。
setBackground(Color) - 类 javax.swing.table.JTableHeader.AccessibleJTableHeader.AccessibleJTableHeaderEntry 中的方法

setBackground(Color) - 类 javax.swing.text.LabelView 中的方法
设置视图的背景色。
setBackground(MutableAttributeSet, Color) - 类 javax.swing.text.StyleConstants 中的静态方法
设置背景色。
setBackground(Color) - 类 javax.swing.tree.DefaultTreeCellRenderer 中的方法
创建子类,以便将 ColorUIResource 映射为 null。


楼主写的setBackgroud()应该是component中的。
Ramy_1224 2007-10-06
  • 打赏
  • 举报
回复
这问题方法错误我已经改过来了 可是还不能够实现 还有就是方法参数 (ActionEvent e)也有错误
给我错误提示 ActionListener cannot be resolved to a type 想不明白为什么
方法参数也给我这样错误提示! 还望各位帮忙
lihaifeng0412 2007-10-06
  • 打赏
  • 举报
回复
johnsoncr 2007-10-06
  • 打赏
  • 举报
回复
继承自Component的类一般都有setBackground()方法,你在查API文档时,有时候在当前类中没找到相应的方法,你就去它的基类中查找!
public void actionPerformen(ActionEvent e) //actionPerformen拼写错误。应该是actionPerformed

62,623

社区成员

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

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