⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 checkmaker.java

📁 提供 精通Java Web动态图表编程 一书的源代码, 大家赶快下载呀
💻 JAVA
字号:
// Fig. 3.02_02_02: CheckMaker.java
// Java Applet Web图表实例4:生成支票

import java.awt.*; // 引入 java.awt包中所有的类
import javax.swing.*; // 引入 javax.swing包中所有的类
import java.util.*; //引入java.util包中所有的类
import java.text.*; //引入java.text包中的所有的类

public class CheckMaker extends JApplet
{
  Image checkPNG;
  Image offImage;
  Graphics offGraphics;

  int appletWidth = 740, appletHeight = 270;
  String subjectName = "应付货款";
  String partnerSubjectName = "应收货款";
  String receiver = "联想计算机公司";
  String payBank = "中国工商银行重庆市分行";
  String payFor = "购买联想计算机";
  String accountant = "篮猫";
  String supervisor = "大脸猫";

  Date issuedDate = new Date();
  int year;
  int month;
  int day;
  double amount = 6437192.08d;

  String accountNumber = "渝工行2004010178930";
  String chineseAmount = "陆佰肆拾叁万柒仟壹佰玖拾贰圆零角捌分";

  NumberFormat moneyFormat = NumberFormat.getCurrencyInstance(Locale.PRC);

  DateToChinese dtc = new DateToChinese();

  // 初始化绘图缓冲区
  public void init()
  {
    checkPNG = getImage(getDocumentBase(), "check.jpg");
    offImage = createImage(appletWidth, appletHeight);
    offGraphics = offImage.getGraphics();
    year = issuedDate.getYear() + 1900;
    month = issuedDate.getMonth() + 1;
    day = issuedDate.getDate();
  }

  public void paint(Graphics g)
  {
    // 调用父类的 paint 方法
    super.paint(g);
    update(g);

  } // paint 方法结束

  public void drawLeft()
  {
    offGraphics.setFont(new Font("宋体", Font.PLAIN, 12));

    // 绘制科目
    offGraphics.drawString(subjectName, 85, 80);

    // 绘制对方科目
    offGraphics.drawString(partnerSubjectName, 85, 108);

    // 绘制出票日期
    offGraphics.drawString("" + year, 77, 133);
    offGraphics.drawString("" + month, 115, 133);
    offGraphics.drawString("" + day, 140, 133);

    // 绘制收款人
    offGraphics.drawString(receiver, 70, 165);

    // 绘制付款金额
    offGraphics.drawString(moneyFormat.format(amount), 70, 188);

    // 绘制付款用途
    offGraphics.drawString(payFor, 70, 208);

    // 绘制会计人员
    offGraphics.drawString(accountant, 60, 255);

    // 绘制主管
    offGraphics.drawString(supervisor, 125, 255);
  }

  public void drawRight()
  {

    // 绘制中文日期
    String cYear = dtc.getCapitalNumber(year);
    offGraphics.drawString(cYear, 307, 68);

    String cMonth = dtc.getMonthNumber(month);
    offGraphics.drawString(cMonth, 378, 68);

    String cDay = dtc.getDayNumber(day);
    offGraphics.drawString(cDay, 432, 68);

    // 绘制付款行名称
    offGraphics.drawString(payBank, 585, 68);

    // 绘制收款人
    offGraphics.drawString(receiver, 255, 88);

    // 绘制出票人账号
    offGraphics.drawString(accountNumber, 585, 88);

    // 绘制付款用途
    offGraphics.drawString(payFor, 240, 150);

    // 绘制付款金额(中文大写数字)
    offGraphics.setFont(new Font("黑体", Font.PLAIN, 16));
    offGraphics.drawString(chineseAmount, 260, 115);

    // 绘制付款金额(阿拉伯小写数字)
    offGraphics.setFont(new Font("宋体", Font.PLAIN, 14));
   
    String amountOutput = moneyFormat.format(amount);

    int j = 0;
    for (int i = amountOutput.length() - 1; i >= 0; i--)
    {
      String s = "" + amountOutput.charAt(i);

      // 跳过小数点
      if (s.equals(".")||s.equals(","))
      {
        continue;
      }
      offGraphics.drawString(s, 710-j * 15, 127);
      j++;
    }
  }

  public void update(Graphics g)
  {
    // 绘制标题区域
    offGraphics.drawImage(checkPNG, 0, 0, this);
    offGraphics.setColor(Color.BLACK);

    drawLeft();

    drawRight();

    // 输出缓冲区图像
    g.drawImage(offImage, 0, 0, null);
  }

} //  CheckMaker 类结束

/**************************************************************************
 * (C) Copyright 2004-2005 by Jingkui Zhong(钟京馗) and Huan Tang(唐桓).  *
 * All Rights Reserved.                                                   *
 *                                                                        *
 * DISCLAIMER: The authors of this code have used their                   *
 * best efforts in preparing the code. These efforts include the          *
 * development, research, and testing of the theories and programs        *
 * to determine their effectiveness. The authors and publisher make       *
 * no warranty of any kind, expressed or implied, with regard to these    *
 * programs or to the documentation contained in these codes. The authors *
 * shall not be liable in any event for incidental or consequential       *
 * damages in connection with, or arising out of, the furnishing,         *
 * performance, or use of these programs.                                 *
 **************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -