Cutehf 2015-01-17 08:11 采纳率: 100%
浏览 1886
已采纳

新手求教大神,java事件监听问题

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;

public class EventModelDemo implements ActionListener{
JLabel tips=new JLabel("请单击下面的按钮");
JButton b1=new JButton("确定");
JButton b2=new JButton("取消");

    public static void main(String[]args){
        EventModelDemo demo=new EventModelDemo();
        demo.initUI();
    }
  void initUI(){
        BaseFrame f=new BaseFrame("事件处理模型演示");
        f.setLayout(new FlowLayout());
        b1.addActionListener(this);
        b2.addActionListener(this);
        f.add(tips);
        f.add(b1);
        f.add(b2);
        f.showMe();

    }
    public void actionPerform(ActionEvent e){
        if(e.getSource()==b1){
            tips.setText("你单击了”"+b1.getText()+"”");

        }else if(e.getSource()==b2){
            tips.setText("你单击了“"+b2.getText()+"”");
        }
    }

    }
    在EventModelDemo出提示:The type EventModelDemo must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)
  • 写回答

3条回答 默认 最新

  • bdmh 移动开发领域优质创作者 2015-01-17 08:40
    关注

    你继承自ActionListener接口,所以你要实现ActionListener接口中的方法,你肯定有的方法还未实现

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?