1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TransparentWindow extends JWindow implements FocusListener,
MouseMotionListener, MouseListener, ActionListener {
private Image img, tim;
private String s = "yo !";
private boolean _isSpeaking = false;
private Graphics _graphic;
private Point _point;
private Robot _r;
private final JPopupMenu menu = new JPopupMenu();
public TransparentWindow() {
setBounds(800, 170, 150, 150);
getContentPane().setLayout(new BorderLayout());
try {
_r = new Robot();
} catch (AWTException awe) {
System.out.println("robot exception...");
}
capture();
addMouseMotionListener(this);
addMouseListener(this);
addFocusListener(this);
setVisible(true);
// Create and add a menu item
JMenuItem item = new JMenuItem("Dis bonjour !");
item.addActionListener(this);
menu.add(item);
item = new JMenuItem("Wizz du Munix");
item.addActionListener(this);
menu.add(item);
menu.addSeparator();
item = new JMenuItem("Cacher le Munix");
item.addActionListener(this);
menu.add(item);
}
public JWindow getMe() {
return this;
}
public void mouseDragged(MouseEvent m) {
if (_point == null)
return;
Point p = m.getPoint();
int x = getX() + p.x - _point.x;
int y = getY() + p.y - _point.y;
setLocation(x, y);
paintP(getGraphics());
}
public void mouseMoved(MouseEvent m) {
}
public void mouseClicked(MouseEvent m) {
}
public void mouseEntered(MouseEvent m) {
}
public void mouseExited(MouseEvent m) {
}
public void mouseReleased(MouseEvent m) {
_point = null;
if (m.getButton() == MouseEvent.BUTTON3)
if (m.isPopupTrigger()) {
menu.show(m.getComponent(), m.getX(), m.getY());
}
}
public void mousePressed(MouseEvent m) {
_point = m.getPoint();
if (m.isPopupTrigger()) {
menu.show(m.getComponent(), m.getX(), m.getY());
}
}
public void focusGained(FocusEvent fe) {
setSize(0, 0);
capture();
setSize(100, 100);
}
public void focusLost(FocusEvent fe) {
}
public void capture() {
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
img = _r.createScreenCapture(new Rectangle(0, 0, d.width, d.height));
}
public void captureX() {
Rectangle rect = getBounds();
setVisible(false);
Thread.yield();
Image xmg = _r.createScreenCapture(rect);
img.getGraphics().drawImage(xmg, rect.x, rect.y, rect.width,
rect.height, null);
setVisible(true);
}
public void paint(Graphics g) {
Rectangle rect = g.getClipBounds();
if (tim == null) {
tim = createImage(getWidth(), getHeight());
_graphic = tim.getGraphics();
}
if (!rect.getSize().equals(getSize()))
captureX();
else
paintP(g);
}
public void paintP(Graphics g) {
_graphic.drawImage(img, 0, 0, getWidth(), getHeight(), getX(), getY(),
getX() + getWidth(), getY() + getHeight(), null);
// corps
_graphic.setColor(Color.black);
_graphic.fillOval(10, 20, 70, 80);
//bras
_graphic.fillOval(5, 50, 20, 10);
_graphic.fillOval(65, 50, 20, 10);
//yeux
_graphic.setColor(Color.white);
_graphic.fillOval(32, 28, 17, 17);
_graphic.fillOval(45, 30, 13, 13);
// ventre
_graphic.fillOval(20, 48, 50, 50);
//noir des yeux
_graphic.setColor(Color.black);
_graphic.fillOval(37, 32, 10, 10);
_graphic.fillOval(45, 33, 6, 6);
//jambes
_graphic.setColor(Color.orange);
_graphic.fillOval(15, 90, 20, 10);
_graphic.fillOval(55, 90, 20, 10);
//bec
_graphic.fillOval(41, 40, 9, 12);
_graphic.setFont(new Font("Arial", Font.BOLD, 14));
_graphic.setColor(Color.gray);
if (_isSpeaking){
_graphic.setColor(Color.gray);
_graphic.fillOval(50, 0, 70, 30);
_graphic.fillOval(60, 20, 15, 15);
_graphic.setColor(Color.white);
_graphic.drawString(s, 60, 20);
}
g.drawImage(tim, 0, 0, null);
}
public void update(Graphics g) {
this.paint(g);
}
public static void main(String[] args) {
new TransparentWindow();
}
/*
* overrided method
*/
public void actionPerformed(ActionEvent arg0) {
if (arg0.getActionCommand().equalsIgnoreCase("dis bonjour !")) {
_isSpeaking = true;
s = "Coucou";
this.paintP(getGraphics());
} else if (arg0.getActionCommand().equalsIgnoreCase("cacher le munix")) {
System.exit(0);
} else if (arg0.getActionCommand().equalsIgnoreCase("wizz du Munix")) {
new Wizz(this).start();
}
}
} |
Partager