我正在努力实现以下目标
http://www.qksnap.com/i/3hunq/4ld0v/screenshot.png
我目前能够使用以下代码在半透明玻璃板背景上成功绘制矩形:
protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g.setColor(Color.black); // black background
g.fillRect(0, 0, frame.getWidth(), frame.getHeight());
g2.setColor(Color.GREEN.darker());
if (getRect() != null && isDrawing()) {
g2.draw(getRect()); // draw our rectangle (simple Rectangle class)
}
g2.dispose();
}
Run Code Online (Sandbox Code Playgroud)
然而,哪个效果很好,我希望矩形内的区域完全透明,而外部仍然变暗,就像上面的截图一样.
有任何想法吗?