小王子同学 2023-03-21 20:20 采纳率: 0%
浏览 19

java功能移植问题咨询。

使用java怎么编写一个包含水印的记事本程序?目前记事本功能已经实现,水印添加部分移植到记事本程序中之后,运行没有显示,各位指导一下。

以下是添加水印的部分代码

@Override
    // public class MyPanel extends JPanel {
    public void paint(Graphics g) {
        super.paint(g);

        // Get the size of the text area
        int textAreaWidth = jf.getWidth();
        int textAreaHeight = jf.getHeight();
        // int textAreaWidth = 800;
        // int textAreaHeight = 800;

        // Create a new BufferedImage to hold the watermark and text
        BufferedImage bufferedImage = new BufferedImage(textAreaWidth, textAreaHeight,
                BufferedImage.TYPE_INT_ARGB);

        // Draw the text onto the buffered image
        Graphics2D g2d = bufferedImage.createGraphics();
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setFont(watermarkFont);
        g2d.setColor(watermarkColor);
        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
        // 将文字倾斜30度
        g2d.rotate(Math.toRadians(-30), jf.getWidth() / 2, jf.getHeight() / 2);
        // g2d.rotate(Math.toRadians(-30), 800 / 2, 800 / 2);
        g2d.drawString(watermarkText, 20, textAreaHeight - 210);

        // Draw the text area onto the buffered image
        jf.print(g2d);

        // Draw the buffered image onto the main window
        g.drawImage(bufferedImage, 100, 100, null);

        // 释放资源
        // g2d.dispose();
    }

  • 写回答

1条回答 默认 最新

  • threenewbee 2023-03-22 01:08
    关注

    paint里面下断点调试下,有没有运行进来。

    评论

报告相同问题?

问题事件

  • 创建了问题 3月21日

悬赏问题

  • ¥15 数据量少可以用MK趋势分析吗
  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
  • ¥15 大智慧怎么编写一个选股程序
  • ¥100 python 调用 cgps 命令获取 实时位置信息
  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
  • ¥20 ensp怎么配置让PC1和PC2通讯上
  • ¥50 有没有适合匹配类似图中的运动规律的图像处理算法
  • ¥15 dnat基础问题,本机发出,别人返回的包,不能命中