关于抽象类的问题!
我用JCREACTOR编译这两个程序时,她都说“类不是抽象的,和方法不能被重写”!请师兄师姐帮我看看,错在哪?在线等待你的回答!!先谢谢大家了!
程序1:
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class MyCanvas
implements KeyListener,MouseListener{
Canvas c;
String s="";
TextField t;
public static void main(String args[]){
Frame f=new Frame("Canvas");
MyCanvas mc=new MyCanvas();
mc.c=new Canvas();
mc.t=new TextField();
f.add("South",mc.t);
f.setSize(500,300);
mc.c.addMouseListener(mc);
mc.c.addKeyListener(mc);
f.setVisible(true);
}
//实现KeyListener接口中的方法
public void KeyTyped(KeyEvent ev){
t.setText("keyTyped");
s+=ev.getKeyChar();
//将用户键入的字符写到画布上
c.getGraphics().drawString(s,0,20);
}
public void keyPressed(KeyEvent ev){}
public void keyReleased(KeyEvent ev){
t.setText("keyReleased");
}
//实现MouseListener接口中的方法
public void mouseClicked(MouseEvent ev){
t.setText("mouseClicked");
//强制画布获取输入焦点
c.requestFocus();
}
public void mousePressed(MouseEvent ev){
t.setText("mousePressed");
}
public void mouseReleased(MouseEvent ev){
t.setText("mouseReleased");
}
public void mouseEntered(MouseEvent ev){
t.setText("mouseEntered");
}
public void mouseExited(MouseEvent ev){
t.setText("mouseExited");
}
}
程序2:
import java.awt.*;
import java.awt.event.*;
public class TextExample
implements ActionListener,TextListener{
Frame f;
TextField tf1;
TextArea ta1,ta2;
static public void main(String args[]){
TextExample te=new TextExample();
te.go();
}
public void go(){
f=new Frame("Text Example");
f.setLayout(new FlowLayout());
tf1=new TextField("Init",20);
tf1.addActionListener(this);
tf1.addTextListener(this);
ta1=new TextArea("Inital text",4,30);
ta1.addTextListener(this);
ta2=new TextArea("Only horizontal scrollbar",4,30,
TextArea.SCROLLBARS_HORIZONTAL_ONLY);
f.add(tf1);
f.add(ta1);
f.add(ta2);
f.setSize(300,300);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e){
ta2.append("\nActionPerformed");
}
public void textValuChanged(TextEvent e){
ta2.append("\nTextValueChanged");
}
}