当前位置: 技术问答>java相关
照书输了一段程序,但是编译通不过,说是有一个class没定义让定义成abstract,可是....
来源: 互联网 发布时间:2015-05-09
本文导语: 我定义成abstract 她有说不能生成接口,该别的类型也不对,不是可以不定义类型么?源程序(虽长,但不难看) import java.awt.*; import java.awt.event.*; public class KeyEventTest extends Frame{ private TextArea msgArea; public st...
我定义成abstract 她有说不能生成接口,该别的类型也不对,不是可以不定义类型么?源程序(虽长,但不难看)
import java.awt.*;
import java.awt.event.*;
public class KeyEventTest extends Frame{
private TextArea msgArea;
public static void main (String args[]){
KeyEventTest test=new KeyEventTest();
test.setSize(300,300);
test.setVisible(true);
}
public KeyEventTest(){//構造関数
msgArea=new TextArea();
msgArea.setEnabled(false);
add(msgArea,BorderLayout.CENTER);
Button b=new Button("test");
b.addKeyListener(new KeyListen(this));
//let Button can deal with keyevent
add(b,BorderLayout.SOUTH);//add a Button
}
public void ShowMessage(String str){
msgArea.append(str+"n");
}
}
class KeyListen implements KeyListener{ ////问题所在
//recived the class of keylistener
private KeyEventTest parent;//conect with keyeventtest
public KeyListen(KeyEventTest p){//構造関数
parent=p;
}
public void KeyPressed(KeyEvent e){
//実現keylistener の mothod
}
public void KeyReleaed(KeyEvent e){
//実現keylistener の mothod //
parent.ShowMessage("key char="+e.getKeyChar());
parent.ShowMessage("key code="+e.getKeyCode());
parent.ShowMessage("modifier="+e.getModifiers());
}
public void keyType(KeyEvent e){//実現keylistener のmethod
}
}
import java.awt.*;
import java.awt.event.*;
public class KeyEventTest extends Frame{
private TextArea msgArea;
public static void main (String args[]){
KeyEventTest test=new KeyEventTest();
test.setSize(300,300);
test.setVisible(true);
}
public KeyEventTest(){//構造関数
msgArea=new TextArea();
msgArea.setEnabled(false);
add(msgArea,BorderLayout.CENTER);
Button b=new Button("test");
b.addKeyListener(new KeyListen(this));
//let Button can deal with keyevent
add(b,BorderLayout.SOUTH);//add a Button
}
public void ShowMessage(String str){
msgArea.append(str+"n");
}
}
class KeyListen implements KeyListener{ ////问题所在
//recived the class of keylistener
private KeyEventTest parent;//conect with keyeventtest
public KeyListen(KeyEventTest p){//構造関数
parent=p;
}
public void KeyPressed(KeyEvent e){
//実現keylistener の mothod
}
public void KeyReleaed(KeyEvent e){
//実現keylistener の mothod //
parent.ShowMessage("key char="+e.getKeyChar());
parent.ShowMessage("key code="+e.getKeyCode());
parent.ShowMessage("modifier="+e.getModifiers());
}
public void keyType(KeyEvent e){//実現keylistener のmethod
}
}
|
class KeyListen implements KeyListener{ ////ÎÊÌâËùÔÚ
//recived the class of keylistener
private KeyEventTest parent;//conect with keyeventtest
public KeyListen(KeyEventTest p){//˜‹ÔìévÊý
parent=p;
}
public void keyPressed(KeyEvent e){
//Œg¬Fkeylistener ¤Î¡¡mothod
}
public void keyReleased(KeyEvent e){
//Œg¬Fkeylistener ¤Î¡¡mothod //
parent.ShowMessage("key char="+e.getKeyChar());
parent.ShowMessage("key code="+e.getKeyCode());
parent.ShowMessage("modifier="+e.getModifiers());
}
public void keyTyped(KeyEvent e){//Œg¬Fkeylistener ¤Îmethod
}
}
真受不了你,抄书都抄错了!!!!!!!!!!上面的验证通过!!!!!!!!!
//recived the class of keylistener
private KeyEventTest parent;//conect with keyeventtest
public KeyListen(KeyEventTest p){//˜‹ÔìévÊý
parent=p;
}
public void keyPressed(KeyEvent e){
//Œg¬Fkeylistener ¤Î¡¡mothod
}
public void keyReleased(KeyEvent e){
//Œg¬Fkeylistener ¤Î¡¡mothod //
parent.ShowMessage("key char="+e.getKeyChar());
parent.ShowMessage("key code="+e.getKeyCode());
parent.ShowMessage("modifier="+e.getModifiers());
}
public void keyTyped(KeyEvent e){//Œg¬Fkeylistener ¤Îmethod
}
}
真受不了你,抄书都抄错了!!!!!!!!!!上面的验证通过!!!!!!!!!
|
敲错字符了,keyType 应是 keyTyped。
抽象函数必须被非抽象子类实现.
抽象函数必须被非抽象子类实现.