这是个构造函数?
public runThread(Thread t) {
    if(t==null){
       t= new Thread(this);
       t.start();
    }
}
还是应该为
public void runThread(Thread t){
 ...
}

解决方案 »

  1.   

    没有天理啊!!
    写一段程序贴出来看看?
    public runThread(Thread t) ===> public void runThread(Thread t)
      

  2.   

    package gui;import map.*;
    import java.awt.*;
    import javax.swing.*;/**wo
     *  
     * alin 2003-5-22
     */
    public class GamePanel extends JPanel implements Runnable {
    private Map map;
    private Image[] tileImage;
    private Image[] agentImage;
    private Image[] goodImage;
    int agentX;
    int agentRowNumber;
    int agentY;
    int agentLineNumber;
    int focusX;
    int focusY; private int mapWidth;
    private int mapHigh; private final int UP = 1;
    private final int BELOW = 2;
    private final int LEFT = 3;
    private final int RIGHT = 4;
    private int previousMoveDirection = 0;
    private int agentCurrentPic = 0; Thread runner;
    Thread paintThread;
    private GamePanelMouseEvent mouseEvent; public GamePanel(
    Image[] tI,
    Image[] aI,
    Image[] gI,
    Map mp,
    int agentLN,
    int agentRN) { mouseEvent = new GamePanelMouseEvent(this);
    addMouseListener(mouseEvent); tileImage = tI;
    agentImage = aI;
    goodImage = gI;
    map = mp;
    agentLineNumber = agentLN;
    agentY = agentLN * 32;
    agentRowNumber = agentRN;
    agentX = agentRN * 32; mapHigh = map.tiles.length;
    mapWidth = map.tiles[0].length; MediaTracker track = new MediaTracker(this); for (int k = 0; k < tileImage.length; k++)
    track.addImage(tileImage[k], k); for (int j = 0; j < agentImage.length; j++)
    track.addImage(agentImage[j], tileImage.length + j); for (int m = 0; m < goodImage.length; m++)
    track.addImage(
    goodImage[m],
    tileImage.length + agentImage.length + m);
    try {
    track.waitForAll();
    } catch (InterruptedException e) {
    }

    if(paintThread==null){
    paintThread = new Thread(this);
    paintThread.start();
    }
    } public void paintComponent(Graphics comp) {
    Graphics2D comp2D = (Graphics2D) comp; //&raquo;&shy;&micro;&Oslash;&AElig;¤:)...
    for (int i = 0; i < mapHigh; i++) {
    for (int j = 0; j < mapWidth; j++) {
    comp2D.drawImage(tileImage[map.tiles[i][j].tile],
    //&Igrave;&Oslash;±&eth;×&cent;&Ograve;&acirc;&Otilde;&acirc;&Agrave;&iuml;j&cedil;úi&micro;&Auml;&Euml;&sup3;&ETH;ò!!!-_-
    j * 32, i * 32, this);
    }
    } //&raquo;&shy;agent&Euml;ù&Ocirc;&Uacute;&ETH;&ETH;&Eacute;&Iuml;&Atilde;&aelig;&micro;&Auml;&Icirc;&iuml;&AElig;·&sup2;&atilde;(°ü&Agrave;¨&Otilde;&acirc;&ETH;&ETH;)
    for (int i = 0; i <= agentLineNumber; i++) {
    for (int j = 0; j < mapWidth; j++) {
    if (map.tiles[i][j].good1 != -1)
    comp2D.drawImage(
    goodImage[map.tiles[i][j].good1],
    j * 32,
    i * 32,
    this);
    }
    }
    //&raquo;&shy;agent
    comp2D.drawImage(
    agentImage[agentCurrentPic],
    agentX,
    agentY - 16,
    this); //&raquo;&shy;agent&Euml;ù&Ocirc;&Uacute;&ETH;&ETH;&Iuml;&Acirc;&Atilde;&aelig;&micro;&Auml;&Icirc;&iuml;&AElig;·&sup2;&atilde;
    if (agentLineNumber != mapHigh - 1) {
    for (int i = agentLineNumber + 1; i < mapHigh; i++) {
    for (int j = 0; j < mapWidth; j++)
    if (map.tiles[i][j].good1 != -1)
    comp2D.drawImage(
    goodImage[map.tiles[i][j].good1],
    j * 32,
    i * 32,
    this);
    }
    }
    //&raquo;&shy;&Igrave;ì&iquest;&Otilde;&sup2;&atilde;^_^
    for (int i = 0; i < mapHigh; i++) {
    for (int j = 0; j < mapWidth; j++) {
    if (map.tiles[i][j].good2 != -1)
    comp2D.drawImage(
    goodImage[map.tiles[i][j].good2],
    j * 32,
    i * 32,
    this);
    }
    }
    } public void run() {
    while(paintThread == Thread.currentThread()){
    repaint();
    pause(20);
    }
    while(runner == Thread.currentThread()) {
    moveAgent();
    //&Iuml;&Acirc;&Atilde;&aelig;&Oacute;&iuml;&frac34;&auml;°&Ntilde;&Egrave;&Euml;&Icirc;&iuml;&frac12;&Aring;·&Aring;&Iuml;&Acirc;:)
    if (previousMoveDirection == LEFT && agentCurrentPic != 6) {
    agentCurrentPic = 6;
    } else if (
    previousMoveDirection == RIGHT && agentCurrentPic != 9) {
    agentCurrentPic = 9;
    } else if (previousMoveDirection == UP && agentCurrentPic != 3) {
    agentCurrentPic = 3;
    } else if (
    previousMoveDirection == BELOW && agentCurrentPic != 0) {
    agentCurrentPic = 0;
    }
    previousMoveDirection = 0;
    stopThread();
    }
    } public void runThread() {
    if (runner == null) {
    runner = new Thread(this);
    runner.start();
    }
    } private void stopThread() {
    if (runner != null) {
    runner = null;
    }
    }
    private void pause(int time) {
    try {
    Thread.sleep(time);
    } catch (InterruptedException e) {
    }
    } public void moveAgent() {
    //&Iacute;&frac14;&AElig;&not;&AElig;&frac12;&Ograve;&AElig;&micro;&Auml;&frac34;à&Agrave;&euml;
    int step = 5;
    //&Ograve;&AElig;&para;&macr;&Ograve;&raquo;&acute;&Icirc;&frac14;&auml;&cedil;&ocirc;&Ecirc;±&frac14;&auml;
    int time = 40;
    //&acute;&aelig;·&Aring;&frac14;&Egrave;&para;¨&sup2;&frac12;·&yen;×&szlig;&Otilde;&acirc;&Ograve;&raquo;&sup2;&frac12;&Icirc;&raquo;&Ouml;&Atilde;
    int stemp;
    int stempTo; if (focusX < agentX) {
    stemp = agentX - step;
    //&frac14;&Ugrave;&Egrave;&ccedil;°&acute;&frac14;&Egrave;&para;¨&sup2;&frac12;·&yen;×&szlig;&Otilde;&acirc;&sup2;&frac12;&sup3;&not;&sup1;&yacute;&Auml;&iquest;±êx×&oslash;±ê&Aacute;&Euml;,&frac34;&Iacute;°&Ntilde;&Otilde;&acirc;&sup2;&frac12;&para;¨&Ocirc;&Uacute;&Auml;&iquest;±ê&acute;&brvbar;
    if (focusX > stemp)
    stemp = focusX;
    stempTo = stemp / 32;
    //&frac14;&Ugrave;&Egrave;&ccedil;&Otilde;&acirc;&sup2;&frac12;&frac12;&oslash;&Egrave;&euml;&sup2;&raquo;&iquest;&Eacute;&frac12;&oslash;&Egrave;&euml;&Ccedil;&oslash;,&Ouml;&ETH;&Ouml;&sup1;&Ograve;&AElig;&para;&macr;,×&cent;&Ograve;&acirc;&Euml;&sup3;&ETH;ò
    if (map.tiles[agentLineNumber][stempTo].block == false) {
    agentX = agentRowNumber * 32;
    changeAgentPic(LEFT);
    pause(time);
    return;
    }
    agentX = stemp;
    agentRowNumber = stempTo;
    changeAgentPic(LEFT);
    pause(time);
    moveAgent();
    } else if (focusX > agentX) {
    stemp = agentX + step;
    if (focusX < stemp)
    stemp = focusX;
    stempTo = stemp / 32;
    if (map.tiles[agentLineNumber][stempTo].block == false) {
    agentX = agentRowNumber * 32;
    changeAgentPic(RIGHT);
    pause(time);
    return;
    }
    agentX = stemp;
    agentRowNumber = stempTo;
    changeAgentPic(RIGHT);
    pause(time);
    moveAgent();
    } else {
    if (focusY < agentY) {
    stemp = agentY - step;
    if (focusY > stemp)
    stemp = focusY;
    stempTo = stemp/32;
    if (map.tiles[stempTo][agentRowNumber].block == false){
    agentY = agentLineNumber*32;
    changeAgentPic(UP);
    pause(time);
    return;
    }
    agentY = stemp;
    agentLineNumber = stempTo;
    changeAgentPic(UP);
    pause(time);
    moveAgent();
    } else if (focusY > agentY) {
    stemp = agentY + step;
    if (focusY < stemp)
    stemp = focusY;
    stempTo = stemp/32;
    if (map.tiles[stempTo][agentRowNumber].block == false){
    agentY = agentLineNumber*32;
    changeAgentPic(BELOW);
    pause(time);
    return;
    }
    agentY = stemp;
    agentLineNumber = stempTo;
    changeAgentPic(BELOW);
    pause(time);
    moveAgent();
    } else {
    return;
    }
    }
    } private void changeAgentPic(int previousDirection) {
    int firstPic = 0;
    int thirdPic = 0;
    if (previousDirection == LEFT) {
    firstPic = 6;
    } else if (previousDirection == RIGHT) {
    firstPic = 9;
    } else if (previousDirection == UP) {
    firstPic = 3;
    } else {
    firstPic = 0;
    }
    thirdPic = firstPic + 2;
    if (previousMoveDirection == previousDirection) {
    agentCurrentPic++;
    if (agentCurrentPic > thirdPic)
    agentCurrentPic = firstPic;
    } else {
    agentCurrentPic = firstPic;
    previousMoveDirection = previousDirection;
    }
    }}
      

  3.   

    看得头晕!!
    能不能用个简单的main...来试试. 很多东西混在一起就不容易看了.(我不是说你的代码不好或有问题,只是难以看出问题,手头没有编译器...)
      

  4.   

    重发..
    package gui;import map.*;
    import java.awt.*;
    import javax.swing.*;/**wo
     *  
     * alin 2003-5-22
     */
    public class GamePanel extends JPanel implements Runnable {
    private Map map;
    private Image[] tileImage;
    private Image[] agentImage;
    private Image[] goodImage;
    int agentX;
    int agentRowNumber;
    int agentY;
    int agentLineNumber;
    int focusX;
    int focusY; private int mapWidth;
    private int mapHigh; private final int UP = 1;
    private final int BELOW = 2;
    private final int LEFT = 3;
    private final int RIGHT = 4;
    private int previousMoveDirection = 0;
    private int agentCurrentPic = 0; Thread runner;
    Thread paintThread;
    private GamePanelMouseEvent mouseEvent; public GamePanel(
    Image[] tI,
    Image[] aI,
    Image[] gI,
    Map mp,
    int agentLN,
    int agentRN) { mouseEvent = new GamePanelMouseEvent(this);
    addMouseListener(mouseEvent); tileImage = tI;
    agentImage = aI;
    goodImage = gI;
    map = mp;
    agentLineNumber = agentLN;
    agentY = agentLN * 32;
    agentRowNumber = agentRN;
    agentX = agentRN * 32; mapHigh = map.tiles.length;
    mapWidth = map.tiles[0].length; MediaTracker track = new MediaTracker(this); for (int k = 0; k < tileImage.length; k++)
    track.addImage(tileImage[k], k); for (int j = 0; j < agentImage.length; j++)
    track.addImage(agentImage[j], tileImage.length + j); for (int m = 0; m < goodImage.length; m++)
    track.addImage(
    goodImage[m],
    tileImage.length + agentImage.length + m);
    try {
    track.waitForAll();
    } catch (InterruptedException e) {
    }

    if(paintThread==null){
    paintThread = new Thread(this);
    paintThread.start();
    }
    } public void paintComponent(Graphics comp) {
    Graphics2D comp2D = (Graphics2D) comp; //画地皮:)...
    for (int i = 0; i < mapHigh; i++) {
    for (int j = 0; j < mapWidth; j++) {
    comp2D.drawImage(tileImage[map.tiles[i][j].tile],
    //特别注意这里j跟i的顺序!!!-_-
    j * 32, i * 32, this);
    }
    } //画agent所在行上面的物品层(包括这行)
    for (int i = 0; i <= agentLineNumber; i++) {
    for (int j = 0; j < mapWidth; j++) {
    if (map.tiles[i][j].good1 != -1)
    comp2D.drawImage(
    goodImage[map.tiles[i][j].good1],
    j * 32,
    i * 32,
    this);
    }
    }
    //画agent
    comp2D.drawImage(
    agentImage[agentCurrentPic],
    agentX,
    agentY - 16,
    this); //画agent所在行下面的物品层
    if (agentLineNumber != mapHigh - 1) {
    for (int i = agentLineNumber + 1; i < mapHigh; i++) {
    for (int j = 0; j < mapWidth; j++)
    if (map.tiles[i][j].good1 != -1)
    comp2D.drawImage(
    goodImage[map.tiles[i][j].good1],
    j * 32,
    i * 32,
    this);
    }
    }
    //画天空层^_^
    for (int i = 0; i < mapHigh; i++) {
    for (int j = 0; j < mapWidth; j++) {
    if (map.tiles[i][j].good2 != -1)
    comp2D.drawImage(
    goodImage[map.tiles[i][j].good2],
    j * 32,
    i * 32,
    this);
    }
    }
    } public void run() {
    while(paintThread == Thread.currentThread()){
    repaint();
    pause(20);
    }
    while(runner == Thread.currentThread()) {
    moveAgent();
    //下面语句把人物脚放下:)
    if (previousMoveDirection == LEFT && agentCurrentPic != 6) {
    agentCurrentPic = 6;
    } else if (
    previousMoveDirection == RIGHT && agentCurrentPic != 9) {
    agentCurrentPic = 9;
    } else if (previousMoveDirection == UP && agentCurrentPic != 3) {
    agentCurrentPic = 3;
    } else if (
    previousMoveDirection == BELOW && agentCurrentPic != 0) {
    agentCurrentPic = 0;
    }
    previousMoveDirection = 0;
    stopThread();
    }
    } public void runThread() {
    if (runner == null) {
    runner = new Thread(this);
    runner.start();
    }
    } private void stopThread() {
    if (runner != null) {
    runner = null;
    }
    }
    private void pause(int time) {
    try {
    Thread.sleep(time);
    } catch (InterruptedException e) {
    }
    } public void moveAgent() {
    //图片平移的距离
    int step = 5;
    //移动一次间隔时间
    int time = 40;
    //存放既定步伐走这一步位置
    int stemp;
    int stempTo; if (focusX < agentX) {
    stemp = agentX - step;
    //假如按既定步伐走这步超过目标x坐标了,就把这步定在目标处
    if (focusX > stemp)
    stemp = focusX;
    stempTo = stemp / 32;
    //假如这步进入不可进入区,中止移动,注意顺序
    if (map.tiles[agentLineNumber][stempTo].block == false) {
    agentX = agentRowNumber * 32;
    changeAgentPic(LEFT);
    pause(time);
    return;
    }
    agentX = stemp;
    agentRowNumber = stempTo;
    changeAgentPic(LEFT);
    pause(time);
    moveAgent();
    } else if (focusX > agentX) {
    stemp = agentX + step;
    if (focusX < stemp)
    stemp = focusX;
    stempTo = stemp / 32;
    if (map.tiles[agentLineNumber][stempTo].block == false) {
    agentX = agentRowNumber * 32;
    changeAgentPic(RIGHT);
    pause(time);
    return;
    }
    agentX = stemp;
    agentRowNumber = stempTo;
    changeAgentPic(RIGHT);
    pause(time);
    moveAgent();
    } else {
    if (focusY < agentY) {
    stemp = agentY - step;
    if (focusY > stemp)
    stemp = focusY;
    stempTo = stemp/32;
    if (map.tiles[stempTo][agentRowNumber].block == false){
    agentY = agentLineNumber*32;
    changeAgentPic(UP);
    pause(time);
    return;
    }
    agentY = stemp;
    agentLineNumber = stempTo;
    changeAgentPic(UP);
    pause(time);
    moveAgent();
    } else if (focusY > agentY) {
    stemp = agentY + step;
    if (focusY < stemp)
    stemp = focusY;
    stempTo = stemp/32;
    if (map.tiles[stempTo][agentRowNumber].block == false){
    agentY = agentLineNumber*32;
    changeAgentPic(BELOW);
    pause(time);
    return;
    }
    agentY = stemp;
    agentLineNumber = stempTo;
    changeAgentPic(BELOW);
    pause(time);
    moveAgent();
    } else {
    return;
    }
    }
    } private void changeAgentPic(int previousDirection) {
    int firstPic = 0;
    int thirdPic = 0;
    if (previousDirection == LEFT) {
    firstPic = 6;
    } else if (previousDirection == RIGHT) {
    firstPic = 9;
    } else if (previousDirection == UP) {
    firstPic = 3;
    } else {
    firstPic = 0;
    }
    thirdPic = firstPic + 2;
    if (previousMoveDirection == previousDirection) {
    agentCurrentPic++;
    if (agentCurrentPic > thirdPic)
    agentCurrentPic = firstPic;
    } else {
    agentCurrentPic = firstPic;
    previousMoveDirection = previousDirection;
    }
    }