首页 \ 问答 \ JFrame无法显示(JFrame not displaying)

JFrame无法显示(JFrame not displaying)

我正在尝试用下载的applet制作游戏。 我改变了一切,直到我没有错误,但是当我运行它时,它显示一个空框架,我不知道什么是错的!

a.java

package game;

import javax.swing.JFrame;

public class a {
public a() {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(500,500);
    frame.add(new b());
    frame.setVisible(true);
}

    public static void main(String [] args) {
    a a = new a();
    }
}

b.java

package game;

import java.awt.Color;
import java.awt.Event;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.JPanel;

public class b extends JPanel implements Runnable {

Thread thread;
static final int TILE_SIZE = 16;
static final int WALL_HEIGHT = 16;
static final int PROJECTIONPLANEWIDTH = 320;
static final int PROJECTIONPLANEHEIGHT = 200;
static final int ANGLE60 = PROJECTIONPLANEWIDTH;
static final int ANGLE30 = (ANGLE60 / 2);
static final int ANGLE15 = (ANGLE30 / 2);
static final int ANGLE90 = (ANGLE30 * 3);
static final int ANGLE180 = (ANGLE90 * 2);
static final int ANGLE270 = (ANGLE90 * 3);
static final int ANGLE360 = (ANGLE60 * 6);
static final int ANGLE0 = 0;
static final int ANGLE5 = (ANGLE30 / 6);
static final int ANGLE10 = (ANGLE5 * 2);
float fSinTable[];
float fISinTable[];
float fCosTable[];
float fICosTable[];
float fTanTable[];
float fITanTable[];
float fFishTable[];
float fXStepTable[];
float fYStepTable[];
Image fOffscreenImage;
Graphics fOffscreenGraphics;
int fPlayerX = 100;
int fPlayerY = 160;
int fPlayerArc = ANGLE0;
int fPlayerDistanceToTheProjectionPlane = 277;
int fPlayerHeight = 32;
int fPlayerSpeed = 8;
int fProjectionPlaneYCenter = PROJECTIONPLANEHEIGHT / 2;
boolean fKeyUp = false;
boolean fKeyDown = false;
boolean fKeyLeft = false;
boolean fKeyRight = false;
byte fMap[];
static final byte W = 1;                                // wall
static final byte O = 0;                                // opening
static final int MAP_WIDTH = 12;
static final int MAP_HEIGHT = 12;
private boolean run = true;

float arcToRad(float arcAngle) {
    return ((float) (arcAngle * Math.PI) / (float) ANGLE180);
}

public void createTables() {
    int i;
    float radian;
    fSinTable = new float[ANGLE360 + 1];
    fISinTable = new float[ANGLE360 + 1];
    fCosTable = new float[ANGLE360 + 1];
    fICosTable = new float[ANGLE360 + 1];
    fTanTable = new float[ANGLE360 + 1];
    fITanTable = new float[ANGLE360 + 1];
    fFishTable = new float[ANGLE60 + 1];
    fXStepTable = new float[ANGLE360 + 1];
    fYStepTable = new float[ANGLE360 + 1];

    for (i = 0; i <= ANGLE360; i++) {
        radian = arcToRad(i) + (float) (0.0001);
        fSinTable[i] = (float) Math.sin(radian);
        fISinTable[i] = (1.0F / (fSinTable[i]));
        fCosTable[i] = (float) Math.cos(radian);
        fICosTable[i] = (1.0F / (fCosTable[i]));
        fTanTable[i] = (float) Math.tan(radian);
        fITanTable[i] = (1.0F / fTanTable[i]);
        if (i >= ANGLE90 && i < ANGLE270) {
            fXStepTable[i] = (float) (TILE_SIZE / fTanTable[i]);
            if (fXStepTable[i] > 0) {
                fXStepTable[i] = -fXStepTable[i];
            }
        } else {
            fXStepTable[i] = (float) (TILE_SIZE / fTanTable[i]);
            if (fXStepTable[i] < 0) {
                fXStepTable[i] = -fXStepTable[i];
            }
        }
        if (i >= ANGLE0 && i < ANGLE180) {
            fYStepTable[i] = (float) (TILE_SIZE * fTanTable[i]);
            if (fYStepTable[i] < 0) {
                fYStepTable[i] = -fYStepTable[i];
            }
        } else {
            fYStepTable[i] = (float) (TILE_SIZE * fTanTable[i]);
            if (fYStepTable[i] > 0) {
                fYStepTable[i] = -fYStepTable[i];
            }
        }
    }

    for (i = -ANGLE30; i <= ANGLE30; i++) {
        radian = arcToRad(i);
        fFishTable[i + ANGLE30] = (float) (1.0F / Math.cos(radian));
    }

    byte[] map = {
        W, W, W, W, W, W, W, W, W, W, W, W,
        W, O, O, O, O, O, O, O, O, O, O, W,
        W, O, O, O, O, O, O, O, O, O, O, W,
        W, O, O, O, O, O, O, O, W, O, O, W,
        W, O, O, W, O, W, O, O, W, O, O, W,
        W, O, O, W, O, W, W, O, W, O, O, W,
        W, O, O, W, O, O, W, O, W, O, O, W,
        W, O, O, O, W, O, W, O, W, O, O, W,
        W, O, O, O, W, O, W, O, W, O, O, W,
        W, O, O, O, W, W, W, O, W, O, O, W,
        W, O, O, O, O, O, O, O, O, O, O, W,
        W, W, W, W, W, W, W, W, W, W, W, W
    };
    fMap = map;
}

public void start() {
    createTables();
    thread = new Thread(this);
    thread.start();
}

public void run() {
    start();
    fOffscreenImage = createImage(size().width, size().height);
    fOffscreenGraphics = fOffscreenImage.getGraphics();

    while (true) {
        if (fKeyLeft) {
            if ((fPlayerArc -= ANGLE10) < ANGLE0) {
                fPlayerArc += ANGLE360;
            }
        } else if (fKeyRight) {
            if ((fPlayerArc += ANGLE10) >= ANGLE360) {
                fPlayerArc -= ANGLE360;
            }
        }

        float playerXDir = fCosTable[fPlayerArc];
        float playerYDir = fSinTable[fPlayerArc];

        if (fKeyUp) {
            fPlayerX += (int) (playerXDir * fPlayerSpeed);
            fPlayerY += (int) (playerYDir * fPlayerSpeed);
        } else if (fKeyDown) {
            fPlayerX -= (int) (playerXDir * fPlayerSpeed);
            fPlayerY -= (int) (playerYDir * fPlayerSpeed);
        }

        render();
        try {
            Thread.sleep(50);
        } catch (Exception sleepProblem) {
            System.out.println("Sleep problem");
        }
    }
}

public void drawBackground() {
    int c = 25;
    int r;
    for (r = 0; r < PROJECTIONPLANEHEIGHT / 2; r += 10) {
        fOffscreenGraphics.setColor(new Color(c, 125, 225));
        fOffscreenGraphics.fillRect(0, r, PROJECTIONPLANEWIDTH, 10);
        c += 20;
    }
    c = 22;
    for (; r < PROJECTIONPLANEHEIGHT; r += 15) {
        fOffscreenGraphics.setColor(new Color(c, 20, 20));
        fOffscreenGraphics.fillRect(0, r, PROJECTIONPLANEWIDTH, 15);
        c += 15;
    }
}

public void render() {
    drawBackground();

    int verticalGrid;
    int horizontalGrid;
    int distToNextVerticalGrid;
    int distToNextHorizontalGrid;
    float xIntersection;
    float yIntersection;
    float distToNextXIntersection;
    float distToNextYIntersection;

    int xGridIndex;
    int yGridIndex;

    float distToVerticalGridBeingHit;
    float distToHorizontalGridBeingHit;

    int castArc, castColumn;

    castArc = fPlayerArc;
    castArc -= ANGLE30;
    if (castArc < 0) {
        castArc = ANGLE360 + castArc;
    }
    for (castColumn = 0; castColumn < PROJECTIONPLANEWIDTH; castColumn += 5) {
        if (castArc > ANGLE0 && castArc < ANGLE180) {
            horizontalGrid = (fPlayerY / TILE_SIZE) * TILE_SIZE + TILE_SIZE;
            distToNextHorizontalGrid = TILE_SIZE;
            float xtemp = fITanTable[castArc] * (horizontalGrid - fPlayerY);
            xIntersection = xtemp + fPlayerX;
        } else {
            horizontalGrid = (fPlayerY / TILE_SIZE) * TILE_SIZE;
            distToNextHorizontalGrid = -TILE_SIZE;

            float xtemp = fITanTable[castArc] * (horizontalGrid - fPlayerY);
            xIntersection = xtemp + fPlayerX;

            horizontalGrid--;
        }
        if (castArc == ANGLE0 || castArc == ANGLE180) {
            distToHorizontalGridBeingHit = 9999999F;
        } else {
            distToNextXIntersection = fXStepTable[castArc];
            while (true) {
                xGridIndex = (int) (xIntersection / TILE_SIZE);
                yGridIndex = (horizontalGrid / TILE_SIZE);
                if ((xGridIndex >= MAP_WIDTH)
                        || (yGridIndex >= MAP_HEIGHT)
                        || xGridIndex < 0 || yGridIndex < 0) {
                    distToHorizontalGridBeingHit = Float.MAX_VALUE;
                    break;
                } else if ((fMap[yGridIndex * MAP_WIDTH + xGridIndex]) != O) {
                    distToHorizontalGridBeingHit = (xIntersection - fPlayerX) * fICosTable[castArc];
                    break;
                }
                else {
                    xIntersection += distToNextXIntersection;
                    horizontalGrid += distToNextHorizontalGrid;
                }
            }
        }

        if (castArc < ANGLE90 || castArc > ANGLE270) {
            verticalGrid = TILE_SIZE + (fPlayerX / TILE_SIZE) * TILE_SIZE;
            distToNextVerticalGrid = TILE_SIZE;

            float ytemp = fTanTable[castArc] * (verticalGrid - fPlayerX);
            yIntersection = ytemp + fPlayerY;
        }
        else {
            verticalGrid = (fPlayerX / TILE_SIZE) * TILE_SIZE;
            distToNextVerticalGrid = -TILE_SIZE;

            float ytemp = fTanTable[castArc] * (verticalGrid - fPlayerX);
            yIntersection = ytemp + fPlayerY;

            verticalGrid--;
        }
        if (castArc == ANGLE90 || castArc == ANGLE270) {
            distToVerticalGridBeingHit = 9999999;
        } else {
            distToNextYIntersection = fYStepTable[castArc];
            while (true) {
                xGridIndex = (verticalGrid / TILE_SIZE);
                yGridIndex = (int) (yIntersection / TILE_SIZE);

                if ((xGridIndex >= MAP_WIDTH)
                        || (yGridIndex >= MAP_HEIGHT)
                        || xGridIndex < 0 || yGridIndex < 0) {
                    distToVerticalGridBeingHit = Float.MAX_VALUE;
                    break;
                } else if ((fMap[yGridIndex * MAP_WIDTH + xGridIndex]) != O) {
                    distToVerticalGridBeingHit = (yIntersection - fPlayerY) * fISinTable[castArc];
                    break;
                } else {
                    yIntersection += distToNextYIntersection;
                    verticalGrid += distToNextVerticalGrid;
                }
            }
        }

        float scaleFactor;
        float dist;
        int topOfWall;
        int bottomOfWall;
        if (distToHorizontalGridBeingHit < distToVerticalGridBeingHit) {
            dist = distToHorizontalGridBeingHit;
            fOffscreenGraphics.setColor(Color.gray);
        } else {
            dist = distToVerticalGridBeingHit;
            fOffscreenGraphics.setColor(Color.darkGray);
        }
        dist /= fFishTable[castColumn];
        int projectedWallHeight = (int) (WALL_HEIGHT * (float) fPlayerDistanceToTheProjectionPlane / dist);
        bottomOfWall = fProjectionPlaneYCenter + (int) (projectedWallHeight * 0.5F);
        topOfWall = PROJECTIONPLANEHEIGHT - bottomOfWall;
        if (bottomOfWall >= PROJECTIONPLANEHEIGHT) {
            bottomOfWall = PROJECTIONPLANEHEIGHT - 1;
        }
        fOffscreenGraphics.fillRect(castColumn, topOfWall, 5, projectedWallHeight);
        castArc += 5;
        if (castArc >= ANGLE360) {
            castArc -= ANGLE360;
        }
    }
    paint(getGraphics());
}

public void paint(Graphics g) {

    if (fOffscreenImage!=null) g.drawImage(fOffscreenImage, 0, 0, this);
}

  public boolean keyDown(Event evt, int key)
  {
    switch (key)
    {
      case Event.ESCAPE:
        System.exit(0);
      case Event.UP:
        fKeyUp=true;
        break;
      case Event.DOWN:
        fKeyDown=true;
        break;
      case Event.LEFT:
        fKeyLeft=true;
        break;
      case Event.RIGHT:
        fKeyRight=true;
        break;
      default:
    }
    return true;
  }

  public boolean keyUp(Event evt, int key)
  {
    switch (key)
    {
      case Event.UP:
          fKeyUp=false;
          break;
      case Event.DOWN:
          fKeyDown=false;
          break;
      case Event.LEFT:
         fKeyLeft=false;
         break;
      case Event.RIGHT:
         fKeyRight=false;
         break;
      default:
    }
    return true;
  }
}

I am trying to make a game out of a downloaded applet. I changed everything until I got no errors, but when I run it, it show an empty frame and I have no idea whats wrong!

a.java:

package game;

import javax.swing.JFrame;

public class a {
public a() {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(500,500);
    frame.add(new b());
    frame.setVisible(true);
}

    public static void main(String [] args) {
    a a = new a();
    }
}

b.java:

package game;

import java.awt.Color;
import java.awt.Event;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.JPanel;

public class b extends JPanel implements Runnable {

Thread thread;
static final int TILE_SIZE = 16;
static final int WALL_HEIGHT = 16;
static final int PROJECTIONPLANEWIDTH = 320;
static final int PROJECTIONPLANEHEIGHT = 200;
static final int ANGLE60 = PROJECTIONPLANEWIDTH;
static final int ANGLE30 = (ANGLE60 / 2);
static final int ANGLE15 = (ANGLE30 / 2);
static final int ANGLE90 = (ANGLE30 * 3);
static final int ANGLE180 = (ANGLE90 * 2);
static final int ANGLE270 = (ANGLE90 * 3);
static final int ANGLE360 = (ANGLE60 * 6);
static final int ANGLE0 = 0;
static final int ANGLE5 = (ANGLE30 / 6);
static final int ANGLE10 = (ANGLE5 * 2);
float fSinTable[];
float fISinTable[];
float fCosTable[];
float fICosTable[];
float fTanTable[];
float fITanTable[];
float fFishTable[];
float fXStepTable[];
float fYStepTable[];
Image fOffscreenImage;
Graphics fOffscreenGraphics;
int fPlayerX = 100;
int fPlayerY = 160;
int fPlayerArc = ANGLE0;
int fPlayerDistanceToTheProjectionPlane = 277;
int fPlayerHeight = 32;
int fPlayerSpeed = 8;
int fProjectionPlaneYCenter = PROJECTIONPLANEHEIGHT / 2;
boolean fKeyUp = false;
boolean fKeyDown = false;
boolean fKeyLeft = false;
boolean fKeyRight = false;
byte fMap[];
static final byte W = 1;                                // wall
static final byte O = 0;                                // opening
static final int MAP_WIDTH = 12;
static final int MAP_HEIGHT = 12;
private boolean run = true;

float arcToRad(float arcAngle) {
    return ((float) (arcAngle * Math.PI) / (float) ANGLE180);
}

public void createTables() {
    int i;
    float radian;
    fSinTable = new float[ANGLE360 + 1];
    fISinTable = new float[ANGLE360 + 1];
    fCosTable = new float[ANGLE360 + 1];
    fICosTable = new float[ANGLE360 + 1];
    fTanTable = new float[ANGLE360 + 1];
    fITanTable = new float[ANGLE360 + 1];
    fFishTable = new float[ANGLE60 + 1];
    fXStepTable = new float[ANGLE360 + 1];
    fYStepTable = new float[ANGLE360 + 1];

    for (i = 0; i <= ANGLE360; i++) {
        radian = arcToRad(i) + (float) (0.0001);
        fSinTable[i] = (float) Math.sin(radian);
        fISinTable[i] = (1.0F / (fSinTable[i]));
        fCosTable[i] = (float) Math.cos(radian);
        fICosTable[i] = (1.0F / (fCosTable[i]));
        fTanTable[i] = (float) Math.tan(radian);
        fITanTable[i] = (1.0F / fTanTable[i]);
        if (i >= ANGLE90 && i < ANGLE270) {
            fXStepTable[i] = (float) (TILE_SIZE / fTanTable[i]);
            if (fXStepTable[i] > 0) {
                fXStepTable[i] = -fXStepTable[i];
            }
        } else {
            fXStepTable[i] = (float) (TILE_SIZE / fTanTable[i]);
            if (fXStepTable[i] < 0) {
                fXStepTable[i] = -fXStepTable[i];
            }
        }
        if (i >= ANGLE0 && i < ANGLE180) {
            fYStepTable[i] = (float) (TILE_SIZE * fTanTable[i]);
            if (fYStepTable[i] < 0) {
                fYStepTable[i] = -fYStepTable[i];
            }
        } else {
            fYStepTable[i] = (float) (TILE_SIZE * fTanTable[i]);
            if (fYStepTable[i] > 0) {
                fYStepTable[i] = -fYStepTable[i];
            }
        }
    }

    for (i = -ANGLE30; i <= ANGLE30; i++) {
        radian = arcToRad(i);
        fFishTable[i + ANGLE30] = (float) (1.0F / Math.cos(radian));
    }

    byte[] map = {
        W, W, W, W, W, W, W, W, W, W, W, W,
        W, O, O, O, O, O, O, O, O, O, O, W,
        W, O, O, O, O, O, O, O, O, O, O, W,
        W, O, O, O, O, O, O, O, W, O, O, W,
        W, O, O, W, O, W, O, O, W, O, O, W,
        W, O, O, W, O, W, W, O, W, O, O, W,
        W, O, O, W, O, O, W, O, W, O, O, W,
        W, O, O, O, W, O, W, O, W, O, O, W,
        W, O, O, O, W, O, W, O, W, O, O, W,
        W, O, O, O, W, W, W, O, W, O, O, W,
        W, O, O, O, O, O, O, O, O, O, O, W,
        W, W, W, W, W, W, W, W, W, W, W, W
    };
    fMap = map;
}

public void start() {
    createTables();
    thread = new Thread(this);
    thread.start();
}

public void run() {
    start();
    fOffscreenImage = createImage(size().width, size().height);
    fOffscreenGraphics = fOffscreenImage.getGraphics();

    while (true) {
        if (fKeyLeft) {
            if ((fPlayerArc -= ANGLE10) < ANGLE0) {
                fPlayerArc += ANGLE360;
            }
        } else if (fKeyRight) {
            if ((fPlayerArc += ANGLE10) >= ANGLE360) {
                fPlayerArc -= ANGLE360;
            }
        }

        float playerXDir = fCosTable[fPlayerArc];
        float playerYDir = fSinTable[fPlayerArc];

        if (fKeyUp) {
            fPlayerX += (int) (playerXDir * fPlayerSpeed);
            fPlayerY += (int) (playerYDir * fPlayerSpeed);
        } else if (fKeyDown) {
            fPlayerX -= (int) (playerXDir * fPlayerSpeed);
            fPlayerY -= (int) (playerYDir * fPlayerSpeed);
        }

        render();
        try {
            Thread.sleep(50);
        } catch (Exception sleepProblem) {
            System.out.println("Sleep problem");
        }
    }
}

public void drawBackground() {
    int c = 25;
    int r;
    for (r = 0; r < PROJECTIONPLANEHEIGHT / 2; r += 10) {
        fOffscreenGraphics.setColor(new Color(c, 125, 225));
        fOffscreenGraphics.fillRect(0, r, PROJECTIONPLANEWIDTH, 10);
        c += 20;
    }
    c = 22;
    for (; r < PROJECTIONPLANEHEIGHT; r += 15) {
        fOffscreenGraphics.setColor(new Color(c, 20, 20));
        fOffscreenGraphics.fillRect(0, r, PROJECTIONPLANEWIDTH, 15);
        c += 15;
    }
}

public void render() {
    drawBackground();

    int verticalGrid;
    int horizontalGrid;
    int distToNextVerticalGrid;
    int distToNextHorizontalGrid;
    float xIntersection;
    float yIntersection;
    float distToNextXIntersection;
    float distToNextYIntersection;

    int xGridIndex;
    int yGridIndex;

    float distToVerticalGridBeingHit;
    float distToHorizontalGridBeingHit;

    int castArc, castColumn;

    castArc = fPlayerArc;
    castArc -= ANGLE30;
    if (castArc < 0) {
        castArc = ANGLE360 + castArc;
    }
    for (castColumn = 0; castColumn < PROJECTIONPLANEWIDTH; castColumn += 5) {
        if (castArc > ANGLE0 && castArc < ANGLE180) {
            horizontalGrid = (fPlayerY / TILE_SIZE) * TILE_SIZE + TILE_SIZE;
            distToNextHorizontalGrid = TILE_SIZE;
            float xtemp = fITanTable[castArc] * (horizontalGrid - fPlayerY);
            xIntersection = xtemp + fPlayerX;
        } else {
            horizontalGrid = (fPlayerY / TILE_SIZE) * TILE_SIZE;
            distToNextHorizontalGrid = -TILE_SIZE;

            float xtemp = fITanTable[castArc] * (horizontalGrid - fPlayerY);
            xIntersection = xtemp + fPlayerX;

            horizontalGrid--;
        }
        if (castArc == ANGLE0 || castArc == ANGLE180) {
            distToHorizontalGridBeingHit = 9999999F;
        } else {
            distToNextXIntersection = fXStepTable[castArc];
            while (true) {
                xGridIndex = (int) (xIntersection / TILE_SIZE);
                yGridIndex = (horizontalGrid / TILE_SIZE);
                if ((xGridIndex >= MAP_WIDTH)
                        || (yGridIndex >= MAP_HEIGHT)
                        || xGridIndex < 0 || yGridIndex < 0) {
                    distToHorizontalGridBeingHit = Float.MAX_VALUE;
                    break;
                } else if ((fMap[yGridIndex * MAP_WIDTH + xGridIndex]) != O) {
                    distToHorizontalGridBeingHit = (xIntersection - fPlayerX) * fICosTable[castArc];
                    break;
                }
                else {
                    xIntersection += distToNextXIntersection;
                    horizontalGrid += distToNextHorizontalGrid;
                }
            }
        }

        if (castArc < ANGLE90 || castArc > ANGLE270) {
            verticalGrid = TILE_SIZE + (fPlayerX / TILE_SIZE) * TILE_SIZE;
            distToNextVerticalGrid = TILE_SIZE;

            float ytemp = fTanTable[castArc] * (verticalGrid - fPlayerX);
            yIntersection = ytemp + fPlayerY;
        }
        else {
            verticalGrid = (fPlayerX / TILE_SIZE) * TILE_SIZE;
            distToNextVerticalGrid = -TILE_SIZE;

            float ytemp = fTanTable[castArc] * (verticalGrid - fPlayerX);
            yIntersection = ytemp + fPlayerY;

            verticalGrid--;
        }
        if (castArc == ANGLE90 || castArc == ANGLE270) {
            distToVerticalGridBeingHit = 9999999;
        } else {
            distToNextYIntersection = fYStepTable[castArc];
            while (true) {
                xGridIndex = (verticalGrid / TILE_SIZE);
                yGridIndex = (int) (yIntersection / TILE_SIZE);

                if ((xGridIndex >= MAP_WIDTH)
                        || (yGridIndex >= MAP_HEIGHT)
                        || xGridIndex < 0 || yGridIndex < 0) {
                    distToVerticalGridBeingHit = Float.MAX_VALUE;
                    break;
                } else if ((fMap[yGridIndex * MAP_WIDTH + xGridIndex]) != O) {
                    distToVerticalGridBeingHit = (yIntersection - fPlayerY) * fISinTable[castArc];
                    break;
                } else {
                    yIntersection += distToNextYIntersection;
                    verticalGrid += distToNextVerticalGrid;
                }
            }
        }

        float scaleFactor;
        float dist;
        int topOfWall;
        int bottomOfWall;
        if (distToHorizontalGridBeingHit < distToVerticalGridBeingHit) {
            dist = distToHorizontalGridBeingHit;
            fOffscreenGraphics.setColor(Color.gray);
        } else {
            dist = distToVerticalGridBeingHit;
            fOffscreenGraphics.setColor(Color.darkGray);
        }
        dist /= fFishTable[castColumn];
        int projectedWallHeight = (int) (WALL_HEIGHT * (float) fPlayerDistanceToTheProjectionPlane / dist);
        bottomOfWall = fProjectionPlaneYCenter + (int) (projectedWallHeight * 0.5F);
        topOfWall = PROJECTIONPLANEHEIGHT - bottomOfWall;
        if (bottomOfWall >= PROJECTIONPLANEHEIGHT) {
            bottomOfWall = PROJECTIONPLANEHEIGHT - 1;
        }
        fOffscreenGraphics.fillRect(castColumn, topOfWall, 5, projectedWallHeight);
        castArc += 5;
        if (castArc >= ANGLE360) {
            castArc -= ANGLE360;
        }
    }
    paint(getGraphics());
}

public void paint(Graphics g) {

    if (fOffscreenImage!=null) g.drawImage(fOffscreenImage, 0, 0, this);
}

  public boolean keyDown(Event evt, int key)
  {
    switch (key)
    {
      case Event.ESCAPE:
        System.exit(0);
      case Event.UP:
        fKeyUp=true;
        break;
      case Event.DOWN:
        fKeyDown=true;
        break;
      case Event.LEFT:
        fKeyLeft=true;
        break;
      case Event.RIGHT:
        fKeyRight=true;
        break;
      default:
    }
    return true;
  }

  public boolean keyUp(Event evt, int key)
  {
    switch (key)
    {
      case Event.UP:
          fKeyUp=false;
          break;
      case Event.DOWN:
          fKeyDown=false;
          break;
      case Event.LEFT:
         fKeyLeft=false;
         break;
      case Event.RIGHT:
         fKeyRight=false;
         break;
      default:
    }
    return true;
  }
}

原文:https://stackoverflow.com/questions/12661100
更新时间:2021-07-08 16:07

最满意答案

SQL Server可能正在使用缓存的执行计划(基于您第一次从视图中选择某些内容。该表的大小可能已经增大,不再使用最有效的计划,因此性能较慢)。

您可以使用以下命令刷新视图:

sp_refreshview [ @viewname = ] 'viewname'

或者完全重建视图并再次运行以生成新的执行计划,但是稍后您可能会遇到相同的性能问题。 本文将详细介绍可能发生的情况:

http://www.sql-server-performance.com/2007/views-general/

http://technet.microsoft.com/en-us/library/ms187821.aspx


SQL Server may be using an cached execution plan (Based upon the first time you selected something from the view. That table may have grown in size and is no longer using the most efficient plan, hence the slow performance).

You could refresh the view using:

sp_refreshview [ @viewname = ] 'viewname'

Or rebuild the view entirely and run it again to generate a fresh execution plan, however you may run into the same performance trouble later on. This article describes what could be happening in further detail:

http://www.sql-server-performance.com/2007/views-general/

http://technet.microsoft.com/en-us/library/ms187821.aspx

相关问答

更多
  • 在这种情况下,您应该忽略子树的成本。 即使在实际计划中,它们也只是基于估算。 根据您对STATISTICS IO输出的说法,例如,访问Table2的操作员的实际执行次数为0 。 但是,该计划可能会估计执行次数= 1。 (选择运算符后,您可以在SSMS的属性窗口中查看估计和实际数字) 如果计划的某些分支对执行次数的估计不足,则可以尝试使用#temp表,以便考虑列统计信息。 您可以通过添加一些辅助变量和OPTION (RECOMPILE)来获得更具代表性的子树成本,但它们仍然只能与建模假设和估计一样准确。 例如 ...
  • 根据统计数据输出,第一个更快。 在那里寻找的东西包括经过的时间和读/写的数量。 第一查询: SQL Server Execution Times: CPU time = 203 ms, elapsed time = 198 ms. 第二个查询: SQL Server Execution Times: CPU time = 109 ms, elapsed time = 250 ms. 第一个查询执行得稍快。 毫秒可能看起来微不足道,但考虑到每天运行数千次的查询,所有这些微小的秒数将开始快速加起来。 要查找的另 ...
  • SELECT [F1],[F2],[F3] FROM [T2] WHERE ...需要三列,而IX_T2_F1_F2只包含其中两列。 当涉及到覆盖未覆盖所需列的所有列的索引时,SQL Server有时会顽固不化。 为了满足查询,它必须将覆盖索引与聚簇索引结合使用,并且(简化一点)涉及的操作越多,查询成本就越高。 它估计扫描一个索引(聚集索引)比使用两个索引便宜,并且您获得了一个带有聚簇索引扫描的计划。 这篇文章进一步讨论了它,SQL Server将在什么时候将覆盖索引与聚簇索引结合使用。 SELECT [F ...
  • 你会经常用这种方法重新编译计划。 我通常会尝试拆分它们,所以你最终得到: DECLARE @condition BIT IF @condition = 1 BEGIN EXEC MyProc1 END ELSE BEGIN EXEC MyProc2 END 这种方式与最终用户没有区别,MyProc1和2获得了他们自己的,适当的缓存执行计划。 一个程序,一个查询。 You'll get plan recompiles often with that approach. I generally ...
  • SET SHOWPLAN_TEXT ON (或单击Display Estimated Execution Plan is SSMS)创建计划而不是执行SQL 因为这会创建#temp SELECT Id INTO #temp FROM table WHERE ... 这会失败 DELETE FROM #temp INNER JOIN table2 ON a=b WHERE ... 因此解决方案是将其添加到顶部(或通过SSMS执行等效操作) SET SHOWPLAN_TEXT OFF GO SET STA ...
  • 问题的标题不是你真正要求的。 您的prod和测试服务器之间有相同的查询计划。 您真正要问的是为什么prod服务器比具有相同查询的测试服务器慢。 在评论中你回答说表和它们的内容在测试和产品之间是相同的。 具体来说,你提到他们有相同的行数。 产品计划显示的返回数据多于测试计划。 返回数据的最大兴趣点是Commerciali_All_Day上的表扫描,它是哈希表的构建输入。 在测试中,它返回725,858行,总大小为47MB。 在prod中它返回728,941行,总大小为120MB。 这是大小的两倍以上,相差3, ...
  • SQL Server可能正在使用缓存的执行计划(基于您第一次从视图中选择某些内容。该表的大小可能已经增大,不再使用最有效的计划,因此性能较慢)。 您可以使用以下命令刷新视图: sp_refreshview [ @viewname = ] 'viewname' 或者完全重建视图并再次运行以生成新的执行计划,但是稍后您可能会遇到相同的性能问题。 本文将详细介绍可能发生的情况: http://www.sql-server-performance.com/2007/views-general/ http://tec ...
  • 只需在SQL Server Management Studio中按ctrl + m即可激活“包含实际执行计划”。 这将显示真实的执行计划,就像任何普通查询一样。 Just press ctrl + m in SQL Server Management Studio to activate "Include Actual Execution Plan". This will show the real execution plan just as with any ordinary query.
  • 使用参数化查询可以最大化缓存计划的机会 SELECT * from MYTasks WHERE IdUser = @UserId AND DATE < @enddate and DATE > @startdate SQL Server确实进行了自动参数化,但对此可能相当保守。 您可以从以下方面了解计划重用 SELECT usecounts, cacheobjtype, objtype, text, query_plan, value as set_options FROM sys.dm_exec_cac ...
  • 正如@James发布的链接中所提到的,有几种方法可以使用简单的cfquery来检索有关执行计划的信息。 要记住几件事: SET SHOWPLAN选项通常应用于会话连接,这意味着如果您使用连接池(这是不合需要的),它们可能会持续超出当前请求。 请务必始终在查询结束时禁用该设置 - 即使发生错误也是如此。 某些SET SHOWPLAN选项返回多个结果集。 CFQuery只返回一个结果集。 因此它可能无法捕获返回的所有数据。 大多数系统视图和过程( sys.dm_exec_sql_text等等)都需要提升权限。 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。