Beispiel #1
0
  @Override
  public void paint(Graphics g) {
    Scanner scan = new Scanner(System.in);
    super.paint(g);
    double rand[][] = new double[WIDTH][HEIGHT];
    int stack[][] = new int[WIDTH][HEIGHT];
    int topx = -1;
    int topy = -1;
    for (double x = 0; x < WIDTH; x++) {
      for (double y = 0; y < HEIGHT; y++) {
        int a = (int) x;
        int b = (int) y;
        rand[a][b] = Math.random();
        if (y == 0 && topy == -1) {
          if (rand[a][b] > 0.5) {
            g.setColor(new Color(255, 255, 255));
            stack[++topx][topy] = 1;

          } else if (rand[a][b] < 0.5) {
            g.setColor(new Color(0, 0, 0));
            stack[++topy][topy] = 0;
          }
        } else if (y != 0 && stack[topy][topy] == 0) {
          g.setColor(new Color(0, 0, 0));
        }

        g.drawLine(a, b, a, b);
      }
    }
  }
Beispiel #2
0
  @Override
  public void paint(Graphics g1) {
    super.paint(g1);
    Graphics2D g = (Graphics2D) g1;

    drawGrid(g);
    drawFunctions(g);
  }
  /**
   * Updates the canvas in response to a request to <code>repaint()</code> it. The canvas is cleared
   * with the current background colour, before <code>paint()</code> is called to add the new
   * contents. Subclasses which override this method should either call this method via <code>
   * super.update(graphics)</code> or re-implement this behaviour, so as to ensure that the canvas
   * is clear before painting takes place.
   *
   * @param graphics the graphics context.
   */
  public void update(Graphics graphics) {
    Dimension size;

    /* Clear the canvas */
    size = getSize();
    graphics.clearRect(0, 0, size.width, size.height);
    /* Call the paint method */
    paint(graphics);
  }
  @Override
  public void paint(Graphics g) {
    super.paint(g);

    if (_fastBitmap != null) {
      drawImage(g, _fastBitmap.toImage());
    } else {
      drawName(g, "Display");
    }
  }
Beispiel #5
0
  public void paint(Graphics g) {

    super.paint(g);

    g.setFont(new Font("기본", Font.BOLD, 50));
    g.setColor(Color.RED);
    g.drawImage(img, 0, 0, this);
    g.drawString("Score : " + Integer.toString(gameBoard.score), 650, 150);
    //		g.drawString("Score : "+ Integer.toString(gameBoard.score), 20, 550);
  }
Beispiel #6
0
 @Override
 public void paint(Graphics g) {
   super.paint(g);
   Graphics2D draw = (Graphics2D) g;
   draw.setColor(Color.WHITE);
   draw.fillRect(0, 0, this.getWidth(), this.getHeight());
   draw.setStroke(new BasicStroke(this.strk_width));
   draw.setColor(this.color);
   draw.draw(this.shape);
 }
 private void drawName(Graphics g, String name) {
   super.paint(g);
   Dimension d = getSize();
   int w = d.width;
   int h = d.height;
   FontMetrics fm = g.getFontMetrics();
   int x = (d.width - fm.stringWidth(name)) / 2;
   int y = (d.height + fm.getMaxAscent() - fm.getMaxDescent()) / 2;
   g.drawString(name, x, y);
   g.drawRect(0, 0, w - 1, h - 1);
 }
 @Override
 public void paint(Graphics pG) {
   super.paint(pG);
   if (mCurrentHint != null) {
     for (int i = 0; i < mCurrentHint.getNbReleased(); i++) {
       for (int j = 0; j < mCurrentHint.getResult().getBlockSize(i); j++) {
         pG.drawImage(
             ImageHelper.getImage(mCurrentHint.getResult().getElement(i)),
             j * PuzzleBuilder.SQUARE_SIZE,
             i * PuzzleBuilder.SQUARE_SIZE,
             this);
       }
     }
   }
 }
Beispiel #9
0
 @Override
 public void paint(Graphics g) {
   super.paint(g);
   g.drawLine(150, 75, 150, 375);
   g.drawLine(120, 375, 400, 375);
   g.drawLine(150, 75, 250, 75);
   g.drawLine(250, 75, 250, 125);
   g.setColor(Color.blue);
   g.drawLine(250, 175, 250, 250);
   g.drawArc(225, 125, 50, 50, 0, 360);
   g.drawLine(250, 200, 225, 175);
   g.drawLine(250, 200, 275, 175);
   g.drawLine(250, 250, 225, 275);
   g.drawLine(250, 250, 275, 275);
   g.drawString("You have won the game", 300, 225);
 }
Beispiel #10
0
  public static void main(String[] args) {
    frame.setLayout(null);
    frame.setSize(1000, 800);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.addKeyListener(
        new KeyListener() {

          @Override
          public void keyTyped(KeyEvent arg0) {}

          @Override
          public void keyReleased(KeyEvent arg0) {
            switch (arg0.getKeyChar()) {
              case 'a':
                buttons[0] = false;
                break;
              case 'w':
                buttons[1] = false;
                break;
              case 'd':
                buttons[2] = false;
                break;
              case 's':
                buttons[3] = false;
                break;
              case '6':
                buttons2[1] = false;
                break;
              case '4':
                buttons2[0] = false;
                break;
              default:
                break;
            }
          }

          @Override
          public void keyPressed(KeyEvent arg0) {
            switch (arg0.getKeyChar()) {
              case 'a':
                buttons[0] = true;
                break;
              case 'w':
                buttons[1] = true;
                break;
              case 'd':
                buttons[2] = true;
                break;
              case 's':
                buttons[3] = true;
                break;
              case '6':
                buttons2[1] = true;
                break;
              case '4':
                buttons2[0] = true;
                break;
              case ' ':
                speed = 0;
                break;
              case '2':
                speed = 4 * lowSpeed;
                break;
              case '3':
                speed = 8 * lowSpeed;
                break;

              default:
                break;
            }
          }
        });
    canvas = new myCanvas(frame);
    canvas.setBounds(0, 0, 1000, 1000);
    frame.add(canvas);

    frame.setVisible(true);
    while (true) {

      double newSpeed =
          Math.max(
              -maxSpeed,
              Math.min(maxSpeed, speed + (buttons[1] ? 0.1 : 0) - (buttons[3] ? 0.1 : 0)));
      ug -= ((buttons[0] ? 1 : 0) - (buttons[2] ? 1 : 0)) * ugSpeed;
      ug2 -= ((buttons2[0] ? 1 : 0) - (buttons2[1] ? 1 : 0)) * ugSpeed2;
      x += (speed + newSpeed) / 2 * Math.cos(ug);
      y += (speed + newSpeed) / 2 * Math.sin(ug);
      speed = newSpeed;
      canvas.paint(canvas.getGraphics());
      try {
        Thread.sleep(25);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }
Beispiel #11
0
 /**
  * Paint the drawing surface on the applet.
  *
  * @param g A graphics object
  */
 public void paint(Graphics g) {
   buffG.clearRect(0, 0, getWidth(), getHeight());
   canvas.paint(buffG);
   g.drawImage(buff, 0, 0, this);
 }