The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the ar
来源:互联网 发布:淘宝美工教学视频 编辑:程序博客网 时间:2024/04/29 08:37
package PopupFrame;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButtonMenuItem;
public class PopupFrame extends JFrame
{
private JRadioButtonMenuItem[] item;
private ButtonGroup buttongroup;
private JPopupMenu popupmenu;
private final Color[] color={Color.BLUE,Color.YELLOW,Color.RED};
public PopupFrame()
{
super("Using JPopupMenus");
ItemHandler handler=new ItemHandler();
String[] colors={"Blue","Yellow","Red"};
item=new JRadioButtonMenuItem[colors.length];
buttongroup=new ButtonGroup();
popupmenu=new JPopupMenu();
for(int count=0;count<item.length;count++)
{
item[count]=new JRadioButtonMenuItem(colors[count]);
popupmenu.add(item[count]);
buttongroup.add(item[count]);
item[count].addActionListener(handler);
}
setBackground(Color.WHITE);
addMouseListener(
new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
checkForTriggerEvent(e);
}
public void mouseReleased(MouseEvent e)
{
checkForTriggerEvent(e);
}
private void checkForTriggerEvent(MouseEvent e)
{
if(e.isPopupTrigger())
{
popupmenu.show(e.getComponent(),e.getX(), e.getY());
}
}
}
);
}
private class ItemHandler
{
public void actionPerformed(ActionEvent e)
{
for(int i=0;i<item.length;i++)
{
if(e.getSource()==item[i])
{
getContentPane().setBackground(color[i]);
return;
}
}
}
}
}
代码如上,但是那是错误代码,出现这个错误的原因是没有在ItemHandler中实现ActionListener接口,在这个方法后面加上implements ActionListener就可以正常运行了
- The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the ar
- 报错 The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the ar
- 报错:The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the ar
- The method setStatus(int) in the type Goods is not applicable for the arguments (Integer)
- The method setClass(Context, Class<?>) in the type Intent is not applicable for the arguments (GameV
- The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the argum
- The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the argum
- The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the argum
- The method setOnKeyListener(View.OnKeyListener) in the type View is not applicable for the argum
- The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the argum
- The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the argum
- The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable for the
- The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the argum
- The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable for the,
- The method load(Class, Serializable) in the type Session is not applicable for the arguments (Class<
- 错误:The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the argum
- The method setClass(Context, Class<?>) in the type Intent is not applicable for the问题
- The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the argument
- 对C++中类型兼容规则的认识
- 高清网络摄像机主流芯片方案之安霸、德仪和海思对比
- 标签(2)
- Uiautomator获取控件对象之instance
- 黑马程序员------Java基础学习------泛型
- The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the ar
- Web Service学习笔记
- Travel hnoi省选集训
- ZOJ:3641Information Sharing(并查集)
- 标签(3)
- Callable接口测试
- 常用限制input的方法
- 2015/03/31 百度广告事业部面试基础问答
- 习题2—13