TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
- 这个Applet的html文件:
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
- <HTML>
- <BODY>
- <APPLET CODE = "CheckMaker.class" WIDTH = "740" HEIGHT = "270">
- </APPLET>
- </BODY>
- </HTML>
- 这个Applet共有两个类文件:
- // Fig. 3.02_02_01: DateToChinese.java
- // 分离阿拉伯数字,并返回相应的中文大写日期
- public class DateToChinese
- {
- private String[] chineseNumber =
- {
- "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "拾"
- };
- public DateToChinese()
- {
- super();
- }
- public String getDayNumber(int day)
- {
- String output = "";
- if (day < 20)
- {
- output += getMonthNumber(day);
- }
- else if (day >= 20 && day < 30)
- {
- output += "贰拾";
- day -= 20;
- if (day == 0)
- {
- return "贰拾";
- }
- output += getCapitalNumber(day);
- }
- else
- {
- output += "叁拾";
- day -= 30;
- if (day == 0)
- {
- return "叁拾";
- }
- output += getCapitalNumber(day);
- }
- return output;
- }
- public String getMonthNumber(int month)
- {
- String output = "";
- if (month > 10)
- {
- output += "拾";
- month -= 10;
- }
- output += getCapitalNumber(month);
- return output;
- }
- // 分离阿拉伯数字,并返回相应的中文大写数字
- public String getCapitalNumber(int number)
- {
- int divisor = 1, digit;
- String output = "";
- //找到"最大的基数"
- for (int i = 1; i < number; i *= 10)
- {
- divisor = i;
- }
- while (divisor >= 1)
- {
- digit = quotient(number, divisor);
- output += chineseNumber[digit];
- number = remainder(number, divisor);
- divisor = quotient(divisor, 10);
- }
- return output;
- } //分离数字结束
- public int quotient(int a, int b)
- {
- return a / b;
- }
- public int remainder(int a, int b)
- {
- return a % b;
- }
- } // end DateToChinese class
- /**************************************************************************
- * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and *
- * Prentice Hall. All Rights Reserved. *
- * *
- * DISCLAIMER: The authors and publisher of this book have used their *
- * best efforts in preparing the book. 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 books. The authors *
- * and publisher 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. *
- *************************************************************************/
复制代码
- // 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 类结束
复制代码
运行图:
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 |
|