JAVA编程出错。
为什么我添加了awt.event包了,然后编程时用ActionListener还回出现ThemethodaddActionListener(ActionListener)...
为什么我添加了awt.event包了,然后编程时用ActionListener还回出现The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (EventTest.ButtonAction)这个问题???
class EventTest extends LayoutManagerTest
{
ButtonAction actionObj;
public EventTest()
{
actionObj =new ButtonAction();
comboBox.addActionListener(actionObj);
buttonObj.addActionListener(actionObj);
}
class ButtonAction implements ActionListener
{
int i=0;
String[][]data={
{"张谨 ","12345678901","女","35 "},
{" "," "," "," "},
{" "," "," "," "},
{" "," "," "," "},
};
头文件
import javax.swing.*;
import java.awt.*;
import java.awt.Event.*;
下面的接上面程序后面
DialogEvent dEObj;
JButton soures;
public void actionPerformed(ActionEvent ev)
{
Object obj=ev.getSource();
if(obj==comboBox)
{
data[i][2]=(String)comboBox.getSelectedItem();
getAppletContext().showStatus("你选择的客户性别为:"+data[i][2]);
return;
} 展开
class EventTest extends LayoutManagerTest
{
ButtonAction actionObj;
public EventTest()
{
actionObj =new ButtonAction();
comboBox.addActionListener(actionObj);
buttonObj.addActionListener(actionObj);
}
class ButtonAction implements ActionListener
{
int i=0;
String[][]data={
{"张谨 ","12345678901","女","35 "},
{" "," "," "," "},
{" "," "," "," "},
{" "," "," "," "},
};
头文件
import javax.swing.*;
import java.awt.*;
import java.awt.Event.*;
下面的接上面程序后面
DialogEvent dEObj;
JButton soures;
public void actionPerformed(ActionEvent ev)
{
Object obj=ev.getSource();
if(obj==comboBox)
{
data[i][2]=(String)comboBox.getSelectedItem();
getAppletContext().showStatus("你选择的客户性别为:"+data[i][2]);
return;
} 展开
5个回答
展开全部
class ButtonAction implements ActionListener
这句话中,你的ButtonAction类继承了ActionListener接口那么必须实现它声明的方法
public void actionPerformed(ActionEvent e)
这句话中,你的ButtonAction类继承了ActionListener接口那么必须实现它声明的方法
public void actionPerformed(ActionEvent e)
追问
这句话在后面有哦
追答
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
这里需要导入这两个包,你都导入了吗
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
参数传的时候写错了,应该是new EventTest.ButtonAction()才对。
来自:求助得到的回答
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
ButtonAction是怎样定义的?
错误提示是ActionListener不能监听ButtonAction类的动作。
错误提示是ActionListener不能监听ButtonAction类的动作。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
正常
actionObj =new ButtonAction();
JComboBox comboBox=new JComboBox();
comboBox.addActionListener(actionObj);
JButton buttonObj=new JButton("dddd");
buttonObj.addActionListener(actionObj);
不知道你的comboBox是哪个类的。
actionObj =new ButtonAction();
JComboBox comboBox=new JComboBox();
comboBox.addActionListener(actionObj);
JButton buttonObj=new JButton("dddd");
buttonObj.addActionListener(actionObj);
不知道你的comboBox是哪个类的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
ActionListener接口实现了?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询