求救啊..编译出错!!
我的是这样的啊!那里错啦.请各位看看!!import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class CanvasTest extends Canvas implements KeyListener
{
int index;
Color color[]={Color.red,Color.green,Color.blue};
public void paint(Graphics g)
{
g.setColor(color[index]);
g.fillRect(0,0,getSize().width,getSize().height);
}
public static void main(String[] args) {
Frame f=new Frame("Canavs");
CanvasTest mc=new CanvasTest();
f.add(mc,BorderLayout.CENTER);
f.setSize(200,200);
mc.requestFocus();
mc.addKeyListener(mc);
f.setVisible(true);
}
public void keyTyped(KeyEvent ev)
{
index++;
if (index==color.length)
{
index =0;
}
repaint();
}
public void keyReleased(KeyEvent ev){ }
public void keyPreeed(KeyEvent ev){ }
}
编译出错!!
Command : "C:\Program Files\Java\jdk1.6.0_03\bin\javac.exe" -classpath "C:\Program Files\Xinox Software\JCreatorV4\MyProjects\ChTest\CanvasTest\classes\;C:\Program Files\Java\jdk1.6.0_03\jre\lib\rt.jar;C:\Program Files\Java\jdk1.6.0_03\lib\dt.jar;C:\Program Files\Java\jdk1.6.0_03\lib\tools.jar;C:\Program Files\Java\jdk1.6.0_03\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.6.0_03\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.6.0_03\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.6.0_03\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.6.0_03\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.6.0_03\lib;C:\Program Files\Java\jdk1.6.0_03\bin;C:\Program Files\Java\jre1.6.0_03\lib" -d "C:\Program Files\Xinox Software\JCreatorV4\MyProjects\ChTest\CanvasTest\classes" @src_canvastest.txt
Directory : "C:\Program Files\Xinox Software\JCreatorV4\MyProjects\ChTest\CanvasTest"
C:\Program Files\Xinox Software\JCreatorV4\MyProjects\ChTest\CanvasTest\src\CanvasTest.java:12: CanvasTest 不是抽象的,并且未覆盖 java.awt.event.KeyListener 中的抽象方法 keyPressed(java.awt.event.KeyEvent)
public class CanvasTest extends Canvas implements KeyListener
^
1 错误
Process completed.
搜索更多相关的解决方案:
编译
----------------解决方案--------------------------------------------------------
。。。。。打错字了 keyPressed
----------------解决方案--------------------------------------------------------
没有覆盖keyPressed方法,覆盖一遍
----------------解决方案--------------------------------------------------------
一楼说的没错 拼写错误
好像就只有红色,不能切换颜色的啊
----------------解决方案--------------------------------------------------------
keyPressed误写成了keyPreeed.这种重写的方法应该是让开发工具去生成的最好了,最好不要手动去敲.
----------------解决方案--------------------------------------------------------