The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the ar
2015-03-31 22:06
246 查看
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就可以正常运行了
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 setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.Builder is not applicable for the arguments
- 报错 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 setOnClickListener(View.OnClickListener) in the type View is not applicable for the argum
- OSCache的源码编译Cache.java 文件报add(Class, T) in the type EventListenerList is not applicable for the arguments 错误的解决
- The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the argum
- The method add(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (i
- The method add(Fragment) in the type ArrayList<Fragment> is not applicable for the arguments (ImageF
- 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 setButton(int, CharSequence, Message) in the type AlertDialog is not applicable for the a
- 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 argu
- 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 replace in the type.. is not applicable for the argument......
- The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the argument
- The method setClass(Context, Class<?>) in the type Intent is not applicable for the问题
- The method create(Context, Uri) in the type MediaPlayer is not applicable for the arguments (new Vie
- The method setOnClickListener(View.OnClickListener) in the type View is not applicable