Пример #1
0
  /* (non-Javadoc)
   *
   * Adds a character to the string buffer
   *
   * @see tools.Tool#keyPressed(java.awt.event.KeyEvent)
   */
  public void keyPressed(KeyEvent e) {
    char nextChar = e.getKeyChar();
    Graphics iBGraphics = canvas.getimageBufferGraphics();
    text.append(nextChar);

    if (e.isShiftDown()) shape.updateBounds(iBGraphics, 18);
    else shape.updateBounds(iBGraphics, 12);

    iBGraphics.drawString(text.toString(), startingPosition.x, startingPosition.y);
    shape.updateText(text);
    canvas.repaint();
  }
Пример #2
0
 /* (non-Javadoc)
  *
  * Returns focus to the drawing canvas and stores the starting location for
  * the text display.
  * @see tools.Tool#mousePressed(java.awt.event.MouseEvent)
  */
 public void mousePressed(MouseEvent e) {
   try {
     shape = new TextShape(canvas.getpenColor());
     shape.setCanvas(canvas);
     canvas.requestFocus();
     startingPosition = e.getPoint();
     Graphics iBGraphics = canvas.getimageBufferGraphics();
     iBGraphics.setFont(font);
     text = new StringBuffer();
     shape.draw(iBGraphics, startingPosition.x - 3, startingPosition.y - 19, 0, 25);
     canvas.addShape(shape);
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }