public boolean keyDown(Event evt, int key) {
    TextField t = (TextField)parent.h.get("keyDown");
    t.setText(evt.toString());
    return true;
   }
    public boolean keyUp(Event evt, int key) {
    TextField t = (TextField)parent.h.get("keyUp");
    t.setText(evt.toString());
    return true;
  }
  public boolean lostFocus(Event evt, Object w) {
    TextField t = (TextField)parent.h.get("lostFocus");
    t.setText(evt.toString());
    return true;
  }
  public boolean gotFocus(Event evt, Object w) {
    TextField t = (TextField)parent.h.get("gotFocus");
    t.setText(evt.toString());
    return true;
  }
  public boolean mouseDown(Event evt,int x,int y) {
    TextField t = (TextField)parent.h.get("mouseDown");
    t.setText(evt.toString());
    return true;
  }

解决方案 »

  1.   

    public boolean mouseDrag(Event evt,int x,int y) {
        TextField t = (TextField)parent.h.get("mouseDrag");
        t.setText(evt.toString());
        return true;
      }
      public boolean mouseEnter(Event evt,int x,int y) {
        TextField t = (TextField)parent.h.get("mouseEnter");
        t.setText(evt.toString());
        return true;
      }
      public boolean mouseExit(Event evt,int x,int y) {
        TextField t = (TextField)parent.h.get("mouseExit");
        t.setText(evt.toString());
        return true;
      }
      public boolean mouseMove(Event evt,int x,int y) {
      TextField t = (TextField)parent.h.get("mouseMove");
        t.setText(evt.toString());
        return true;
      }
      public boolean mouseUp(Event evt,int x,int y) {
        TextField t = (TextField)parent.h.get("mouseUp");
        t.setText(evt.toString());
        return true;
      }
    }
    待续!
      

  2.   

    public class AutoEvent extends Applet {
      Hashtable h = new Hashtable();
      String[] event = {
        "keyDown", "keyUp", "lostFocus", 
        "gotFocus", "mouseDown", "mouseUp", 
        "mouseMove", "mouseDrag", "mouseEnter", 
        "mouseExit"
      };
      MyButton 
        b1 = new MyButton(this, Color.blue, "test1"),
        b2 = new MyButton(this, Color.red, "test2");
      public void init() {
        setLayout(new GridLayout(event.length+1,2));
        for(int i = 0; i < event.length; i++) {
          TextField t = new TextField();
          t.setEditable(false);
          add(new Label(event[i], Label.CENTER)); 
          add(t);
          h.put(event[i], t);
        }
        add(b1);
        add(b2);
      }

    //<applet code=AutoEvent.class width=300 height=200></applet>
    待续!
      

  3.   

    我有几处不明白,谁给我讲明白了,500分送他!
    1、size()是怎么来的?
    2、FontMetrics fm=g.getFontMetrics();
    FontMetrics  是什么类?fm=g.getFontMetrics() 得到了什么属性?
    3、g.fillRoundRect(0,0,size().width,size().height,rnd,rnd);
    这个方法是干什么用的,第一个到第六个变量的作用是什么?
    4、b1 = new MyButton(this, Color.blue, "test1")中的this起什么作用?
    它代表的是什么?
    5、顺便把这句解释一下!
    add(new Label(event[i], Label.CENTER));
    6、Canvas、Dialog、Frame类是作什么的。
    谢谢,哪位大侠让小弟明白了,500分立刻奉送!
    完了!
      

  4.   

    〉1、size()是怎么来的?
       是继承自Canvas的方法,返回Canvas的大小〉2、FontMetrics fm=g.getFontMetrics();
    〉FontMetrics  是什么类?fm=g.getFontMetrics() 得到了什么属性?
        字体资源,用来获取字体的信息,计算字符的长宽等。〉3、g.fillRoundRect(0,0,size().width,size().height,rnd,rnd);
    〉这个方法是干什么用的,第一个到第六个变量的作用是什么?
         画一个园角矩形,参数分别为(左上角X,左上角Y , 宽度, 高度,园角水平半径, 园角垂直半径)〉4、b1 = new MyButton(this, Color.blue, "test1")中的this起什么作用?
    〉它代表的是什么?
          指的是当前的类的实例,就是AutoEvent类的实例  
    〉5、顺便把这句解释一下!
    〉add(new Label(event[i], Label.CENTER));
        把新建一个Label加到当前控件上。Label的文字是居中对齐的。  
      
    〉6、Canvas、Dialog、Frame类是作什么的。
       Canvas是一个画板,可以用于绘制图形。
       Dialog是对话框。
       Frame是窗体,可以最大化,最小化的那个。
    〉谢谢,哪位大侠让小弟明白了,500分立刻奉送!
    完了!
      

  5.   

    1.size(),凡是有的地方,全报错的!
      

  6.   

    那是因为size()是jdk1.1的方法,已经过期了
    替代它的是getSize();
      

  7.   

    >1、size()是怎么来的?
    size()是Component的方法,从1.1开始废除>2、FontMetrics fm=g.getFontMetrics();
    >FontMetrics  是什么类?fm=g.getFontMetrics() 得到了什么属性?
    java.awt.FontMetrics封装了和字体相关的一些信息,在屏幕上绘制的时候会用到这些信息。详细的可以参考java doc。>3、g.fillRoundRect(0,0,size().width,size().height,rnd,rnd);
    >这个方法是干什么用的,第一个到第六个变量的作用是什么?fillRoundRect
    public abstract void fillRoundRect(int x,
                                       int y,
                                       int width,
                                       int height,
                                       int arcWidth,
                                       int arcHeight)
    Fills the specified rounded corner rectangle with the current color. The left and right edges of the rectangle are at x and x + width - 1, respectively. The top and bottom edges of the rectangle are at y and y + height - 1. Parameters:
    x - the x coordinate of the rectangle to be filled.
    y - the y coordinate of the rectangle to be filled.
    width - the width of the rectangle to be filled.
    height - the height of the rectangle to be filled.
    arcWidth - the horizontal diameter of the arc at the four corners.
    arcHeight - the vertical diameter of the arc at the four corners.>4、b1 = new MyButton(this, Color.blue, "test1")中的this起什么作用?
    >它代表的是什么?
    this是AutoEvent类的一个实例,也就是这个applet。
    >5、顺便把这句解释一下!
    >add(new Label(event[i], Label.CENTER));
    这些就是你看到的applet上左边的东西,除了最后一个蓝色的button。
    >6、Canvas、Dialog、Frame类是作什么的。
    Canvas就是一个画布,你可以在上面画任何东西。它也是一个容器,你可以把像lable,button这样的component放在里面。Dialog一般用于从用户那里得到一些输入信息或者告诉用户一些信息。Dialog可以使modal(模态),此时只有dialog是激活的;Dialog也可以是modeless(非模态),此时可以切换到其他的窗口。Frame一般用作程序的主窗口。
      

  8.   

    看起来你的这个代码是jdk1.0的时期的,也许你该找点新东西看看。
      

  9.   

    奇怪,怎么我可以编译、运行呢?我的是jdk1.3.1_03,但是报:
    Note: AutoEvent.java uses or overrides a deprecated API.
    Note: Recompile with -deprecation for details.
    这是怎么回事?覆盖了一个API有什么影响吗?
      

  10.   

    import java.awt.*;
    import java.applet.*;public class IKnow extends Applet {
      public void paint(Graphics g) {
        String label;
    Color color;
    g.setColor(color);
        int rnd=30;
        g.fillRoundRect(0,0,getSize().width,getSize().height,rnd,rnd);
        FontMetrics fm=g.getFontMetrics();
        int width=fm.stringWidth(label);
        int height=fm.getHeight();
        int ascent=fm.getAscent();
        int leading=fm.getLeading();
        int horizMargin=(getSize().width-width)/2;
        int verMargin=(getSize().height-height)/2;
    g.setColor(Color.white);
    g.drawString(label,horizMargin,verMargin+ascent+leading);
        }
    }
    //<applet code=IKnow.class width=300 height=200></applet>帮忙看看为什么这段编译不过,说color、label没有初始化,而我上面的就可以呢?
      

  11.   

    是啊,没初始化啊,java中的局部变量要先被初始化才能用啊。
    String label="It's a label";
    Color color = Color.red;
      

  12.   

    farawayzheng_necas(遥远) ( 
    这位小哥,怎么说也得先把这100分给结了吧?:)