Exemplo n.º 1
0
  /** This internal method begins a new page and prints the header. */
  protected void newpage() {
    page = job.getGraphics(); // Begin the new page
    linenum = 0;
    charnum = 0; // Reset line and char number
    pagenum++; // Increment page number
    page.setFont(headerfont); // Set the header font.
    page.drawString(jobname, x0, headery); // Print job name left justified

    String s = "- " + pagenum + " -"; // Print the page number centered.
    int w = headermetrics.stringWidth(s);
    page.drawString(s, x0 + (this.width - w) / 2, headery);
    w = headermetrics.stringWidth(time); // Print date right justified
    page.drawString(time, x0 + width - w, headery);

    // Draw a line beneath the header
    int y = headery + headermetrics.getDescent() + 1;
    page.drawLine(x0, y, x0 + width, y);

    // Set the basic monospaced font for the rest of the page.
    page.setFont(font);
  }
Exemplo n.º 2
0
 /* paint() - get current time and draw (centered) in Component. */
 public void paint(Graphics g) {
   Calendar myCal = Calendar.getInstance();
   StringBuffer sb = new StringBuffer();
   sb.append(tf.format(myCal.get(Calendar.HOUR)));
   sb.append(':');
   sb.append(tflz.format(myCal.get(Calendar.MINUTE)));
   sb.append(':');
   sb.append(tflz.format(myCal.get(Calendar.SECOND)));
   String s = sb.toString();
   FontMetrics fm = getFontMetrics(getFont());
   int x = (getSize().width - fm.stringWidth(s)) / 2;
   // System.out.println("Size is " + getSize());
   g.drawString(s, x, 10);
 }