Beispiel #1
0
    public void draw(Graphics g, ImageObserver ob) {
      if (!todraw) {
        g.setColor(bgcolor);
        g.drawRect(x, y, w + 2 * border, h + 2 * border);
        g.fillRect(x, y, w + 2 * border, h + 2 * border);
        return;
      }

      if (selected) g.setColor(selected_color);
      else g.setColor(unselected_color);

      g.drawRect(x, y, w + 2 * border, h + 2 * border);
      g.fillRect(x, y, w + 2 * border, h + 2 * border);
      g.drawImage(image[im], x + border, y + border, ob);

      // g.setColor(Color.black);
      // g.drawString("" + im,x+5,y+5);
    }
Beispiel #2
0
  public void paint(Graphics g) {
    Message("Copyright Feb, 2000 Weicon Conan Yuan.", "All Rights Reserved", 7);
    for (int i = 0; i < NUM_LOCATIONS; i++) {
      locs[i].draw(g, this);
      g.setColor(txtcolor);
      if (locs[i].ToDraw()) {
        g.drawString("" + i, locs[i].GetX(), locs[i].GetY() + 10);
      }
    }

    g.setColor(Color.red);
    g.drawRect(400, 200, 30, 30);
    g.fillRect(400, 200, 30, 30);
    Message("Cheat", 4);
  }
Beispiel #3
0
  public void Message(String s, int i) {
    Graphics g = getGraphics();

    if (s == null) {
      g.setColor(bgcolor);
      g.drawRect(400, 50 * i - 10, 200, 10);
      g.fillRect(400, 50 * i - 10, 200, 10);
      return;
    }
    /*
      g.setColor(Color.blue);
      g.drawRect(400,50 * i - 10,200,10);
      g.fillRect(400,50 * i - 10,200,10);
    */
    g.setColor(txtcolor);
    g.drawString(s, 400, 50 * i);
  }
 private final void showpercent(String s, int i, int j) {
   Graphics g = getGraphics();
   Font font = new Font("Helvetica", 1, 13);
   FontMetrics fontmetrics = getFontMetrics(font);
   Font font1 = new Font("Helvetica", 0, 13);
   FontMetrics fontmetrics1 = getFontMetrics(font1);
   if (all || !img && mt.checkAll(true)) {
     all = false;
     if (img || mt.checkAll(true)) {
       g.drawImage(loading, 0, 0, this);
       img = true;
     } else {
       g.setColor(Color.black);
       g.fillRect(0, 0, 512, 344);
     }
     g.setColor(Color.white);
     g.setFont(font);
     String s1 = "RuneScape has been updated!";
     g.drawString(s1, 256 - fontmetrics.stringWidth(s1) / 2, 125);
     s1 = "Please wait - Fetching new files...";
     g.drawString(s1, 256 - fontmetrics.stringWidth(s1) / 2, 140);
     g.setFont(font1);
     s1 = "This may take a few minutes, but only";
     g.drawString(s1, 256 - fontmetrics1.stringWidth(s1) / 2, 165);
     s1 = "needs to be done when the game is updated.";
     g.drawString(s1, 256 - fontmetrics1.stringWidth(s1) / 2, 180);
   }
   Color color = new Color(140, 17, 17);
   g.setColor(color);
   g.drawRect(104, 190, 304, 34);
   g.fillRect(106, 192, j * 3, 30);
   g.setColor(Color.black);
   g.fillRect(106 + j * 3, 192, 300 - j * 3, 30);
   String s2 = "Loading " + s + " - " + i + "%";
   g.setFont(font);
   g.setColor(Color.white);
   g.drawString(s2, 256 - fontmetrics.stringWidth(s2) / 2, 212);
 }
Beispiel #5
0
  // ------------------------------------------------------------------
  // initialize the canvas contents or judge the user's mouse events and respond
  public void paint(Graphics g) {

    // if forceNumber < 0 and !mUp: do nothing until mUp

    // if forceNumber < 0 and mUp (click): start the forces
    if (forceNumber < 0 && mUp) {
      fInit = true;
      mDown = false;
      // next line added 4/17/08 (correction for case of zero force true answer)
      mUp = false;
      forceNumber = 0;
      forceName = forceNames[forceNumber];
      userPosX = tailPosX;
      userPosY = tailPosY;
      numTries = 0;
      messageCanvas.notifyMouseClick(blinkerStrings[forceNumber]);
      // create the force equation and vector objects
      canvasEquation = new CanvasEquation(g);
      canvasVector = new CanvasVector(g);
    }

    // if mouseDown and all forces finished: do end game
    if (mDown && (forceNumber == maxForceNumber + 1)) {
      endGame("OK", cgiScript, problemNo, mouseUpsString);
    }

    // if mouseDown or mouseDrag and really a force:
    //     erase user's old vector & eqn, update position
    if ((mDown || mDrag) && (forceNumber >= 0) && (forceNumber <= maxForceNumber)) {
      messageCanvas.notifyMouseDown(blinkerStrings[forceNumber]);
      eraseUserStuff(g, forceX[0], forceY[0], 0);
      if (numEquations == 2) {
        eraseUserStuff(g, forceX[1], forceY[1], 1);
      }
      userPosX = newUserPosX;
      userPosY = newUserPosY;
    }

    // if browserPaint or forceInit or mouseDown or mouseDrag and really a force:
    //     plot fixed & user's new stuff
    if ((ifBrowserPaint || fInit || mDown || mDrag)
        && (forceNumber >= 0)
        && (forceNumber <= maxForceNumber)) {

      // redraw the userCanvas bounding box and the apparatus
      g.setColor(Color.black);
      g.drawRect(0, 0, userFrameX, userFrameY);
      problemSelector.drawUserApparatus(g);

      // draw the user's previously-done correct vectors
      if (forceNumber > 0) {
        drawDoneVectors(forceNumber - 1, g);
      }

      // draw the user's new vector and equation
      canvasVector.plotVector(tailPosX, tailPosY, userPosX, userPosY, g);
      forceX[0] = p2fX(userPosX, userPosY);
      forceY[0] = p2fY(userPosX, userPosY);
      canvasEquation.plotEquation(g, forceName, units, forceX[0], forceY[0], 0);
      if (numEquations == 2) {
        forceX[1] = (int) Math.round(cost * forceX[0] - sint * forceY[0]);
        forceY[1] = (int) Math.round(sint * forceX[0] + cost * forceY[0]);
        canvasEquation.plotEquation(g, forceName, units, forceX[1], forceY[1], 1);
      }

      // get ready up for new input
      fInit = mDown = mDrag = false;
      if (ifBrowserPaint) {
        ifBrowserPaint = false;
      }
    }

    // if mouseUp, evaluate the user's answer
    if (mUp && (forceNumber >= 0) && (forceNumber < numForces)) {

      // keep track of the mouse ups
      String leftStr = "";
      String rightStr = "";
      String midStr = mouseUpsString.substring(forceNumber, forceNumber + 1);
      if (forceNumber > 0) {
        leftStr = mouseUpsString.substring(0, forceNumber);
      }
      if (forceNumber < numForces - 1) {
        rightStr = mouseUpsString.substring(forceNumber + 1, numForces);
      }
      int numTries = Integer.parseInt(midStr);
      numTries++;
      if (numTries <= 9) {
        midStr = Integer.toString(numTries);
      } else {
        midStr = "9";
      }
      mouseUpsString = leftStr + midStr + rightStr;

      // if correct, cycle to the next force or to the trailer message
      int matchIndex = matchForceComps[forceNumber] - 1;

      int depX = Math.abs(forceX[matchIndex] - truAnsX[forceNumber][matchIndex]);
      int depY = Math.abs(forceY[matchIndex] - truAnsY[forceNumber][matchIndex]);
      if ((depX <= forceTolerance) && (depY <= forceTolerance)) {

        // erase the user's stuff
        for (int n = 0; n <= numEquations - 1; n++) {
          eraseUserStuff(g, forceX[n], forceY[n], n);
        }

        // draw the apparatus
        problemSelector.drawUserApparatus(g);

        // draw the set of correctly done vectors
        drawDoneVectors(forceNumber, g);

        // notify the resultsCanvas of the user's correctly drawn force
        boolean ifResultsDone = false;
        if (forceNumber == maxForceNumber) {
          ifResultsDone = true;
        }
        resultsCanvas.notifyMouseUpOk(
            ifResultsDone,
            forceNumber,
            forceNames,
            units,
            truAnsX,
            truAnsY,
            resultsSpacingStrings,
            numEquations,
            numForces);

        // cycle the force or do the end game
        if (forceNumber < maxForceNumber) {
          forceNumber++;
          numTries = 0;
          forceName = forceNames[forceNumber];
          userPosX = tailPosX;
          userPosY = tailPosY;
          forceX[0] = forceY[0] = forceX[1] = forceY[1] = 0;
          // draw the equation and message for the *next* force
          for (int n = 0; n <= numEquations - 1; n++) {
            canvasEquation.plotEquation(g, forceName, units, forceX[n], forceY[n], n);
          }
          // notify the messageCanvas that there is a new force
          messageCanvas.notifyMouseUpOk(blinkerStrings[forceNumber]);
        } else {
          g.setColor(userTrailerColor);
          g.drawString(userTrailer, userTrailerPosX, userTrailerPosY);
          // notify the messageCanvas that we are all done
          messageCanvas.notifyMouseUpOk("done");
          forceNumber++;
        }
      }
      // if not correct and mode > 1, check # of tries
      else {
        if (problemMode > 1 && numTries >= maxTriesEachForce) {
          endGame("notOK", cgiScript, problemNo, mouseUpsString);
        }
      }
      fInit = mUp = mDown = false;
    }
  }
  /**
   * Paints the image.
   *
   * @param g the rendering surface to use
   * @param a the allocated region to render into
   * @see View#paint
   */
  public void paint(Graphics g, Shape a) {
    Color oldColor = g.getColor();
    fBounds = a.getBounds();
    int border = getBorder();
    int x = fBounds.x + border + getSpace(X_AXIS);
    int y = fBounds.y + border + getSpace(Y_AXIS);
    int width = fWidth;
    int height = fHeight;
    int sel = getSelectionState();

    // Make sure my Component is in the right place:
    /*
    if( fComponent == null ) {
    fComponent = new Component() { };
    fComponent.addMouseListener(this);
    fComponent.addMouseMotionListener(this);
    fComponent.setCursor(Cursor.getDefaultCursor());	// use arrow cursor
    fContainer.add(fComponent);
    }
    fComponent.setBounds(x,y,width,height);
    */
    // If no pixels yet, draw gray outline and icon:
    if (!hasPixels(this)) {
      g.setColor(Color.lightGray);
      g.drawRect(x, y, width - 1, height - 1);
      g.setColor(oldColor);
      loadIcons();
      Icon icon = fImage == null ? sMissingImageIcon : sPendingImageIcon;
      if (icon != null) icon.paintIcon(getContainer(), g, x, y);
    }

    // Draw image:
    if (fImage != null) {
      g.drawImage(fImage, x, y, width, height, this);
      // Use the following instead of g.drawImage when
      // BufferedImageGraphics2D.setXORMode is fixed (4158822).

      //  Use Xor mode when selected/highlighted.
      // ! Could darken image instead, but it would be more expensive.
      /*
      if( sel > 0 )
      g.setXORMode(Color.white);
      g.drawImage(fImage,x, y,
      width,height,this);
      if( sel > 0 )
      g.setPaintMode();
      */
    }

    // If selected exactly, we need a black border & grow-box:
    Color bc = getBorderColor();
    if (sel == 2) {
      // Make sure there's room for a border:
      int delta = 2 - border;
      if (delta > 0) {
        x += delta;
        y += delta;
        width -= delta << 1;
        height -= delta << 1;
        border = 2;
      }
      bc = null;
      g.setColor(Color.black);
      // Draw grow box:
      g.fillRect(x + width - 5, y + height - 5, 5, 5);
    }

    // Draw border:
    if (border > 0) {
      if (bc != null) g.setColor(bc);
      // Draw a thick rectangle:
      for (int i = 1; i <= border; i++)
        g.drawRect(x - i, y - i, width - 1 + i + i, height - 1 + i + i);
      g.setColor(oldColor);
    }
  }