下载地址:https://pan38.com/share.php?code=tprnF
声明:仅可用于学习参考使用!
源码框架:【Ui+完整功能代码】
BankReceiptGenerator.java
import java.text.SimpleDateFormat;
import java.util.Date;
public class BankReceiptGenerator {
public static void main(String[] args) {
// 回执单基本信息
String bankName = "中国银行";
String branchName = "北京分行";
String receiptNumber = "RC20250613001";
String accountName = "张三";
String accountNumber = "6228 4800 **** 1234";
double amount = 5000.00;
String transactionType = "转账";
String payeeName = "李四";
String payeeAccount = "6228 4800 **** 5678";
// 生成当前日期时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
String currentTime = sdf.format(new Date());
// 打印回执单
System.out.println("--------------------------------------------------");
System.out.println(" " + bankName + " " + branchName);
System.out.println("--------------------------------------------------");
System.out.println("回执单号: " + receiptNumber);
System.out.println("交易时间: " + currentTime);
System.out.println("--------------------------------------------------");
System.out.println("账户名称: " + accountName);
System.out.println("账号: " + accountNumber);
System.out.println("交易类型: " + transactionType);
System.out.println("金额: ¥" + String.format("%.2f", amount));
System.out.println("收款人: " + payeeName);
System.out.println("收款账号: " + payeeAccount);
System.out.println("--------------------------------------------------");
System.out.println("备注: 本回执仅作为交易凭证,不作为法律依据");
System.out.println("--------------------------------------------------");
}
}
这段代码会生成带银行回执单内容的窗口并自动截图保存为PNG文件,文件名包含时间戳。需要javax.swing和java.awt图形库支持。
ReceiptScreenshot.java
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import java.text.SimpleDateFormat;
import java.util.Date;
public class ReceiptScreenshot {
public static void main(String[] args) {
// 创建模拟回执单窗口
JFrame frame = new JFrame("电子回执单");
JPanel panel = new JPanel(new BorderLayout(10, 10));
panel.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
// 添加回执单内容
JLabel title = new JLabel("中国银行电子回执单", JLabel.CENTER);
title.setFont(new Font("微软雅黑", Font.BOLD, 20));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time = sdf.format(new Date());
JTextArea content = new JTextArea(
"交易时间: " + time + "\n" +
"交易类型: 转账\n" +
"付款账号: 6222 **** 8888\n" +
"收款账号: 6225 **** 6666\n" +
"交易金额: ¥5,000.00\n" +
"手续费: ¥0.00\n" +
"状态: 交易成功"
);
content.setEditable(false);
content.setFont(new Font("宋体", Font.PLAIN, 16));
panel.add(title, BorderLayout.NORTH);
panel.add(content, BorderLayout.CENTER);
frame.add(panel);
frame.pack();
frame.setVisible(true);
// 截图并保存
try {
Thread.sleep(500); // 等待界面渲染
BufferedImage image = new BufferedImage(
frame.getWidth(),
frame.getHeight(),
BufferedImage.TYPE_INT_RGB
);
frame.paint(image.getGraphics());
ImageIO.write(image, "png", new File("receipt_" + System.currentTimeMillis() + ".png"));
JOptionPane.showMessageDialog(frame, "截图已保存到程序运行目录");
} catch (Exception e) {
e.printStackTrace();
} finally {
frame.dispose();
}
}
}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。