Java学习者论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

手机号码,快捷登录

恭喜Java学习者论坛(https://www.javaxxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,购买链接:点击进入购买VIP会员
JAVA高级面试进阶视频教程Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程

Go语言视频零基础入门到精通

Java架构师3期(课件+源码)

Java开发全终端实战租房项目视频教程

SpringBoot2.X入门到高级使用教程

大数据培训第六期全套视频教程

深度学习(CNN RNN GAN)算法原理

Java亿级流量电商系统视频教程

互联网架构师视频教程

年薪50万Spark2.0从入门到精通

年薪50万!人工智能学习路线教程

年薪50万!大数据从入门到精通学习路线年薪50万!机器学习入门到精通视频教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程 MySQL入门到精通教程
查看: 467|回复: 0

[Swing学习]Java Applet Web图表实例:生成支票

[复制链接]
  • TA的每日心情
    开心
    2021-3-12 23:18
  • 签到天数: 2 天

    [LV.1]初来乍到

    发表于 2014-10-29 23:55:46 | 显示全部楼层 |阅读模式
    1. 这个Applet的html文件:
    2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    3. <HTML>
    4. <BODY>
    5.         <APPLET CODE = "CheckMaker.class" WIDTH = "740" HEIGHT = "270">
    6.         </APPLET>
    7. </BODY>
    8. </HTML>

    9. 这个Applet共有两个类文件:
    10. // Fig. 3.02_02_01: DateToChinese.java
    11. // 分离阿拉伯数字,并返回相应的中文大写日期
    12. public class DateToChinese
    13. {
    14.   private String[] chineseNumber =
    15.   {
    16.     "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "拾"
    17.   };
    18.   public DateToChinese()
    19.   {
    20.     super();
    21.   }
    22.   public String getDayNumber(int day)
    23.   {
    24.     String output = "";
    25.     if (day < 20)
    26.     {
    27.       output += getMonthNumber(day);
    28.     }
    29.     else if (day >= 20 && day < 30)
    30.     {
    31.       output += "贰拾";
    32.       day -= 20;
    33.       if (day == 0)
    34.       {
    35.         return "贰拾";
    36.       }
    37.       output += getCapitalNumber(day);
    38.     }
    39.     else
    40.     {
    41.       output += "叁拾";
    42.       day -= 30;
    43.       if (day == 0)
    44.       {
    45.         return "叁拾";
    46.       }
    47.       output += getCapitalNumber(day);
    48.     }
    49.     return output;
    50.   }
    51.   public String getMonthNumber(int month)
    52.   {
    53.     String output = "";
    54.     if (month > 10)
    55.     {
    56.       output += "拾";
    57.       month -= 10;
    58.     }
    59.     output += getCapitalNumber(month);
    60.     return output;
    61.   }
    62.   // 分离阿拉伯数字,并返回相应的中文大写数字
    63.   public String getCapitalNumber(int number)
    64.   {
    65.     int divisor = 1, digit;
    66.     String output = "";
    67.     //找到"最大的基数"
    68.     for (int i = 1; i < number; i *= 10)
    69.     {
    70.       divisor = i;
    71.     }
    72.     while (divisor >= 1)
    73.     {
    74.       digit = quotient(number, divisor);
    75.       output += chineseNumber[digit];
    76.       number = remainder(number, divisor);
    77.       divisor = quotient(divisor, 10);
    78.     }
    79.     return output;
    80.   } //分离数字结束
    81.   public int quotient(int a, int b)
    82.   {
    83.     return a / b;
    84.   }
    85.   public int remainder(int a, int b)
    86.   {
    87.     return a % b;
    88.   }
    89. } // end DateToChinese class
    90. /**************************************************************************
    91. * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and               *
    92. * Prentice Hall. All Rights Reserved.                                    *
    93. *                                                                        *
    94. * DISCLAIMER: The authors and publisher of this book have used their     *
    95. * best efforts in preparing the book. These efforts include the          *
    96. * development, research, and testing of the theories and programs        *
    97. * to determine their effectiveness. The authors and publisher make       *
    98. * no warranty of any kind, expressed or implied, with regard to these    *
    99. * programs or to the documentation contained in these books. The authors *
    100. * and publisher shall not be liable in any event for incidental or       *
    101. * consequential damages in connection with, or arising out of, the       *
    102. * furnishing, performance, or use of these programs.                     *
    103. *************************************************************************/
    复制代码

       
    1. // Fig. 3.02_02_02: CheckMaker.java
    2. // Java Applet Web图表实例4:生成支票
    3. import java.awt.*; // 引入 java.awt包中所有的类
    4. import javax.swing.*; // 引入 javax.swing包中所有的类
    5. import java.util.*; //引入java.util包中所有的类
    6. import java.text.*; //引入java.text包中的所有的类
    7. public class CheckMaker extends JApplet
    8. {
    9.   Image checkPNG;
    10.   Image offImage;
    11.   Graphics offGraphics;
    12.   int appletWidth = 740, appletHeight = 270;
    13.   String subjectName = "应付货款";
    14.   String partnerSubjectName = "应收货款";
    15.   String receiver = "联想计算机公司";
    16.   String payBank = "中国工商银行重庆市分行";
    17.   String payFor = "购买联想计算机";
    18.   String accountant = "篮猫";
    19.   String supervisor = "大脸猫";
    20.   Date issuedDate = new Date();
    21.   int year;
    22.   int month;
    23.   int day;
    24.   double amount = 6437192.08d;
    25.   String accountNumber = "渝工行2004010178930";
    26.   String chineseAmount = "陆佰肆拾叁万柒仟壹佰玖拾贰圆零角捌分";
    27.   NumberFormat moneyFormat = NumberFormat.getCurrencyInstance(Locale.PRC);
    28.   DateToChinese dtc = new DateToChinese();
    29.   // 初始化绘图缓冲区
    30.   public void init()
    31.   {
    32.     checkPNG = getImage(getDocumentBase(), "check.jpg");
    33.     offImage = createImage(appletWidth, appletHeight);
    34.     offGraphics = offImage.getGraphics();
    35.     year = issuedDate.getYear() + 1900;
    36.     month = issuedDate.getMonth() + 1;
    37.     day = issuedDate.getDate();
    38.   }
    39.   public void paint(Graphics g)
    40.   {
    41.     // 调用父类的 paint 方法
    42.     super.paint(g);
    43.     update(g);
    44.   } // paint 方法结束
    45.   public void drawLeft()
    46.   {
    47.     offGraphics.setFont(new Font("宋体", Font.PLAIN, 12));
    48.     // 绘制科目
    49.     offGraphics.drawString(subjectName, 85, 80);
    50.     // 绘制对方科目
    51.     offGraphics.drawString(partnerSubjectName, 85, 108);
    52.     // 绘制出票日期
    53.     offGraphics.drawString("" + year, 77, 133);
    54.     offGraphics.drawString("" + month, 115, 133);
    55.     offGraphics.drawString("" + day, 140, 133);
    56.     // 绘制收款人
    57.     offGraphics.drawString(receiver, 70, 165);
    58.     // 绘制付款金额
    59.     offGraphics.drawString(moneyFormat.format(amount), 70, 188);
    60.     // 绘制付款用途
    61.     offGraphics.drawString(payFor, 70, 208);
    62.     // 绘制会计人员
    63.     offGraphics.drawString(accountant, 60, 255);
    64.     // 绘制主管
    65.     offGraphics.drawString(supervisor, 125, 255);
    66.   }
    67.   public void drawRight()
    68.   {
    69.     // 绘制中文日期
    70.     String cYear = dtc.getCapitalNumber(year);
    71.     offGraphics.drawString(cYear, 307, 68);
    72.     String cMonth = dtc.getMonthNumber(month);
    73.     offGraphics.drawString(cMonth, 378, 68);
    74.     String cDay = dtc.getDayNumber(day);
    75.     offGraphics.drawString(cDay, 432, 68);
    76.     // 绘制付款行名称
    77.     offGraphics.drawString(payBank, 585, 68);
    78.     // 绘制收款人
    79.     offGraphics.drawString(receiver, 255, 88);
    80.     // 绘制出票人账号
    81.     offGraphics.drawString(accountNumber, 585, 88);
    82.     // 绘制付款用途
    83.     offGraphics.drawString(payFor, 240, 150);
    84.     // 绘制付款金额(中文大写数字)
    85.     offGraphics.setFont(new Font("黑体", Font.PLAIN, 16));
    86.     offGraphics.drawString(chineseAmount, 260, 115);
    87.     // 绘制付款金额(阿拉伯小写数字)
    88.     offGraphics.setFont(new Font("宋体", Font.PLAIN, 14));
    89.    
    90.     String amountOutput = moneyFormat.format(amount);
    91.     int j = 0;
    92.     for (int i = amountOutput.length() - 1; i >= 0; i--)
    93.     {
    94.       String s = "" + amountOutput.charAt(i);
    95.       // 跳过小数点
    96.       if (s.equals(".")||s.equals(","))
    97.       {
    98.         continue;
    99.       }
    100.       offGraphics.drawString(s, 710-j * 15, 127);
    101.       j++;
    102.     }
    103.   }
    104.   public void update(Graphics g)
    105.   {
    106.     // 绘制标题区域
    107.     offGraphics.drawImage(checkPNG, 0, 0, this);
    108.     offGraphics.setColor(Color.BLACK);
    109.     drawLeft();
    110.     drawRight();
    111.     // 输出缓冲区图像
    112.     g.drawImage(offImage, 0, 0, null);
    113.   }
    114. } //  CheckMaker 类结束
    复制代码

       
      
       
       

         
       

         
       
      
      
      
       
      
      运行图:
      
      

      



                            function TempSave(ElementID)
                            {
                                    CommentsPersistDiv.setAttribute("CommentContent",document.getElementById(ElementID).value);
                                    CommentsPersistDiv.save("CommentXMLStore");
                            }
                            function Restore(ElementID)
                            {
                                    CommentsPersistDiv.load("CommentXMLStore");
                                    document.getElementById(ElementID).value=CommentsPersistDiv.getAttribute("CommentContent");
                            }
                   
                      











    源码下载:http://file.javaxxz.com/2014/10/29/235546312.zip
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|手机版|Java学习者论坛 ( 声明:本站资料整理自互联网,用于Java学习者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

    GMT+8, 2024-5-18 19:45 , Processed in 0.452521 second(s), 34 queries .

    Powered by Discuz! X3.4

    © 2001-2017 Comsenz Inc.

    快速回复 返回顶部 返回列表