当前位置: 代码迷 >> J2SE >> 小弟我把接口里的方法都实现了,为什么还出现这样的异常
  详细解决方案

小弟我把接口里的方法都实现了,为什么还出现这样的异常

热度:357   发布时间:2016-04-24 15:28:24.0
我把接口里的方法都实现了,为什么还出现这样的错误
程序出现错误如下:

H:\Java_Test> javac   MyCanvas.java
MyCanvas.java:5:   MyCanvas   is   not   abstract   and   does   not   override   abstract   method
keyTyped(java.awt.event.KeyEvent)   in   java.awt.event.KeyListener
public   class   MyCanvas   implements   KeyListener,MouseListener{
              ^
1   error

源程序如下:
//绘图
import   java.awt.*;
import   java.awt.event.*;
import   java.util.*;
public   class   MyCanvas   implements   KeyListener,MouseListener{
Canvas   c;
String   s   =   " ";
public   static   void   main(String   args[]){
Frame   f   =   new   Frame( "Canvas ");
MyCanvas   mc   =   new   MyCanvas();
mc.c   =   new   Canvas();
f.add( "Center ",mc.c);
f.setSize(150,150);
mc.c.addMouseListener(mc);
mc.c.addKeyListener(mc);
f.setVisible(true);
}

public   void   mouseClicked(MouseEvent   ev){
System.out.println( "MouseClicked ");
c.requestFocus();
}

public   void   KeyTyped(KeyEvent   ev){
System.out.println( "KeyTyped ");
s+=ev.getKeyChar();
c.getGraphics().drawString(s,0,20);
}

public   void   keyPressed(KeyEvent   ev){System.out.println( "KeyPressed ");}
public   void   keyReleased(KeyEvent   ev){System.out.println( "keyReleased ");}
public   void   mousePressed(MouseEvent   ev){System.out.println( "mousePressed ");}
public   void   mouseReleased(MouseEvent   ev){System.out.println( "mouseReleased ");}
public   void   mouseEntered(MouseEvent   ev){System.out.println( "mouseEntered ");}
public   void   mouseExited(MouseEvent   ev){System.out.println( "mouseExited ");}


}

我已经把接口KeyListener,MouseListener里的方法全部实现了,为什么还是出现这样的错误?

------解决方案--------------------
public void keyTyped(java.awt.event.KeyEvent ev){System.out.println( "keyTyped ");}
------解决方案--------------------
KeyTyped的k是小写的
------解决方案--------------------
KeyTyped-->
方法摘要
void keyPressed(KeyEvent e)
按下某个键时调用此方法。
void keyReleased(KeyEvent e)
释放某个键时调用此方法。
void keyTyped(KeyEvent e)
键入某个键时调用此方法。
k大小写拼写错误..
  相关解决方案