可以理解为是是start()驱动run(),但如果你的类(thread)中有定义了start(),那么它将去调用这个start();

解决方案 »

  1.   

    start()对线程进行初始化,然后调用run()
    如果不调用start(),线程永远不会启动
      

  2.   

    Runnable是一个比较灵活的接口,因为它的定义很抽象,如果你愿意去实现它的话,它当然不仅能用于线程;正如“走”不仅适用于人类一样--这也是接口的精髓
    照字面的意思来说,你摘录的那段话是,它为对象提供一种通用的协议,实现它的对象一旦被激活时就能够执行相应的操作。
    确实,它也那样做了
      

  3.   

    楼上所说有点……
    初始化对象是
    ThreadName object = new ThreadName(……);
    此时并不会运行线程
    object.start();
    这时线程才真正被运行,并开始调用run()方法,即启动新线程
    btw:直接调用run方法只是执行同一线程中的内容,却不能启动新线程。
      

  4.   

    interface Runnable 一定用于线程吗
    是的
      

  5.   

    The Runnable interface should be implemented by any
     class whose instances are intended to be executed by a thread.
      

  6.   

    你要把run当普通函数来调用当然行!myClass.run();
    他会作为一个函数调用(不会生称新线成)!
    不过有这个必要吗?
      

  7.   

    例程如下: 
    public class BoxDraw extends Applet implements Runnable,MouseListener, MouseMotionListener
    {
    /* declare graphics object and integers for size of rect
    */
        private Graphics g;
        int firstX=0, firstY=0, lastX, lastY, width=0,height=0; public void init( )
    {
    }    public BoxDraw()
        {
            /* make the applet a listener to mouse events
    */
            addMouseListener(this);
            addMouseMotionListener(this);
        } public void paint(Graphics g)
        {
            /* draw the rectangle with the graphics object
    */
        g.drawRect(firstX,firstY,width,height);
        }   public void run()                           
       {
            /* initialize the graphics object*/
         g = getGraphics();
      }
            public void mousePressed(MouseEvent evt)
        {
            firstX = evt.getX(); // initial width and height
            firstY = evt.getY();
        }    public void mouseDragged(MouseEvent evt)
        {
        lastX=evt.getX();
        width=lastX-firstX; // set the width     lastY=evt.getY();
        height=lastY-firstY; // set the height     repaint();
        }/* these empty methods are here because all the methods in the listener interfaces must be implemented
    */
        public void mouseMoved(MouseEvent evt)
        {
        }
        public void mouseEntered(MouseEvent evt)
        {
        }
        public void mouseExited(MouseEvent evt)
        {
        }
        public void mouseClicked(MouseEvent evt)
        {
        }
        public void mouseReleased(MouseEvent evt)
        {
        }}问:
    1。保留Runnable,删了run(),applet不能运行,这我知道。
     但 删了Runnable,保留run(),applet能运行,Why?  
    2。没看见thread,没有Runnable,run(),照样可以运行,我不知道这个例程饶了个弯想教会我什么?
    3。把BoxDraw()中的两个listener放入init()中运行结果是一样的,没有质的区别吧?
    4。不能用extends MouseAdapter,MouseMotionAdapter从而省掉最后那段多余的程序,只能用
    implements MouseListener,MouseMotionListener ,导致不可缺少最后一段多余的程序?
    5。repaint()是谁的method,I can't find in API documents.
      

  8.   

    1 >>保留Runnable,删了run(),applet不能运行
    当然不行,你得实现run方法。>>但 删了Runnable,保留run(),applet能运行
    只是因为Applet本身有一个start方法,会在init之后或者页面刷新的时候被调用,他启动了run方法。2 >>没看见thread,没有Runnable,run(),照样可以运行
    因为你不知道Applet有个start方法。3 >>把BoxDraw()中的两个listener放入init()中运行结果是一样的
    结果是一样的。但是最好不要这样做。构造函数产生的应该是一个可用的对象。4 >>不能用extends MouseAdapter,MouseMotionAdapter从而省掉最后那段多余的程序,只能用implements MouseListener,MouseMotionListener 
    Java不支持多重继承。但是,你可以使用inner class。像这样:
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent evt) {
            firstX = evt.getX(); // initial width and height
            firstY = evt.getY();
        }
    });5 >>repaint()是谁的method
    repaint是java.awt.Component的方法。
      

  9.   

    4.因为你不能同时 extends 多个 class, 所以 java里用 interface 来实现多重继承!。
      

  10.   

    1,2:Applet运行不需要线程或Runnable,也不需要run()方法。在这个例子中Runnable和run()没有任何意义,可要可不要。