
Signature
Knute Johnson
email s/nospam/linux/
And thus spoke Knute Johnson...
>> So the big question is: How can I fill everything EXCEPT the polygons?
>>
[quoted text clipped - 9 lines]
> mask in a separate JPanel as long as you made sure that the JPanel was
> set to transparent (setOpaque(false)).
Works like a charm, thanks.
Flo
On May 18, 1:44 pm, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
wrote:
> > Hi,
>
[quoted text clipped - 96 lines]
> ------->>>>>>http://www.NewsDemon.com<<<<<<------
> Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
I can't move your alpha hole by mouse dragging
unless I add the line in the mouseDragged()
method:
g2d = mask.createGraphics();
Why is it that? I do not dispose() the g2d in
the code below.
-------------------------------------
/* failed example */
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;
import javax.swing.event.*;
public class Mask extends JPanel {
final BufferedImage img;
final BufferedImage mask;
Graphics2D g2d;
int x, y, x0, y0, x1, y1, size;
Dimension d;
public Mask() throws IOException {
img = ImageIO.read(new File("images/ari3.png"));
d = new Dimension(img.getWidth(),img.getHeight());
setPreferredSize(d);
mask = new BufferedImage(d.width,d.height,
BufferedImage.TYPE_INT_ARGB);
g2d = mask.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(Color.BLACK);
g2d.fillRect(0,0,d.width,d.height);
g2d.setComposite(AlphaComposite.Clear);
x = d.width / 2 -100;
y = d.height / 2 - 100;
size = 200;
g2d.fillOval(x, y, size, size);
Mover mov = new Mover(this);
addMouseListener(mov);
addMouseMotionListener(mov);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(img, 0, 0, this);
g.drawImage(mask, 0, 0, this);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Mask t = new Mask();
f.add(t,BorderLayout.CENTER);
f.pack();
f.setVisible(true);
}
catch (Exception e) {
e.printStackTrace();
}
}
});
}
class Mover extends MouseInputAdapter{
Mask m;
public Mover(Mask mask){
m = mask;
}
public void mousePressed(MouseEvent e){
x0 = x1 = e.getX();
y0 = y1 = e.getY();
}
public void mouseDragged(MouseEvent e){
x1 = x0;
y1 = y0;
x0 = e.getX();
y0 = e.getY();
g2d.setColor(Color.BLACK);
g2d.fillRect(0, 0, d.width, d.height);
g2d.setComposite(AlphaComposite.Clear);
x = x + (x0 - x1);
y = y + (y0 - y1);
g2d.fillOval(x, y, size, size);
m.repaint();
}
}
}
---------------------------------------
Knute Johnson - 26 May 2008 04:47 GMT
> On May 18, 1:44 pm, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
> wrote:
[quoted text clipped - 101 lines]
> Why is it that? I do not dispose() the g2d in
> the code below.
The AlphaCompsoite is killing you. Add the lines below.
> -------------------------------------
> /* failed example */
[quoted text clipped - 27 lines]
> g2d.setColor(Color.BLACK);
> g2d.fillRect(0,0,d.width,d.height);
Composite c = g2d.getComposite();
> g2d.setComposite(AlphaComposite.Clear);
> x = d.width / 2 -100;
> y = d.height / 2 - 100;
> size = 200;
> g2d.fillOval(x, y, size, size);
g2d.setComposite(c);
> Mover mov = new Mover(this);
> addMouseListener(mov);
[quoted text clipped - 46 lines]
> g2d.setColor(Color.BLACK);
> g2d.fillRect(0, 0, d.width, d.height);
Composite c = g2d.getComposite();
> g2d.setComposite(AlphaComposite.Clear);
> x = x + (x0 - x1);
> y = y + (y0 - y1);
> g2d.fillOval(x, y, size, size);
g2d.setComposite(c);
> m.repaint();
> }
> }
> }
> ---------------------------------------
Just like using an AffineTransform, if you don't want it used any more
you have to set it back to the original.

Signature
Knute Johnson
email s/knute/nospam/
hiwa - 26 May 2008 11:40 GMT
On May 26, 12:47 pm, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
wrote:
> > On May 18, 1:44 pm, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
> > wrote:
[quoted text clipped - 220 lines]
> ------->>>>>>http://www.NewsDemon.com<<<<<<------
> Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
BIG THANKS!
BTW, isn't the name of the polar bear at the Berlin zoo Knute? I love
the sound, or the phonetic.
Knute Johnson - 26 May 2008 18:00 GMT
> On May 26, 12:47 pm, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
> wrote:
[quoted text clipped - 188 lines]
> BTW, isn't the name of the polar bear at the Berlin zoo Knute? I love
> the sound, or the phonetic.
Yes he is but his name is spelled in the usual German way, Knut.

Signature
Knute Johnson
email s/knute/nospam/