小编dja*_*ngo的帖子

如何在透明窗口上绘制图像?

我正在尝试在JFrame上使用Graphics2D绘制图像.
但此代码仅显示空白背景.
怎么做?

Java版本:SE-1.6
IDE:Eclipse

我的代码看起来像这样:

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferStrategy;
import java.awt.geom.Line2D;
import java.util.TimerTask;

import javax.swing.JFrame;

public class GraphicTest extends JFrame{

    public static void main(String[] args) {
        GraphicTest gt = new GraphicTest();
        gt.start();
    }

    JFrame frame;
    BufferStrategy strategy;

    GraphicTest(){
        int width = 320;
        int height = 240;

        this.frame = new JFrame("test");

        this.frame.setSize(width, height);
        this.frame.setLocationRelativeTo(null);
        this.frame.setLocation(576, 336);
        this.frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);

        this.frame.setUndecorated(true);
        this.frame.setBackground(new Color(0, 0, 0, 50));

        this.frame.setVisible(true);

        this.frame.setIgnoreRepaint(true);
        this.frame.createBufferStrategy(2);
        this.strategy = this.frame.getBufferStrategy();
    }

    public void onExit(){
        System.exit(0);
    }

    void …
Run Code Online (Sandbox Code Playgroud)

java swing graphics2d bufferstrategy

3
推荐指数
1
解决办法
1802
查看次数

标签 统计

bufferstrategy ×1

graphics2d ×1

java ×1

swing ×1