import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
public class Test extends JPanel {
private static final long serialVersionUID = 4767050156491994899L;
private float alpha = 0.2f;
private float rotate = 0.2f;
private boolean reverse = false;
public Test() {
Thread thread = new Thread() {
public void run() {
while (true) {
if (!reverse) {
alpha -= 0.05f;
} else {
alpha += 0.05f;
}
rotate += 0.1f;
if (rotate > 2 * Math.PI) {
rotate = 0.0f;
;
}
if (alpha < 0 || alpha > 1) {
if (alpha < 0) {
alpha = 0.0f;
} else {
alpha = 1.0f;
}
reverse = !reverse;
}
repaint();
try {
Thread.sleep(50);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
};
thread.start();
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
int x = 0, y = 0;
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
Font font = new Font("tahoma", Font.BOLD, 15);
g2d.setFont(font);
FontMetrics fm = g2d.getFontMetrics();
g2d.drawString("Google VS Baidu", x, y + fm.getAscent());
AffineTransform at = new AffineTransform();
at.translate(getSize().width / 2, getSize().height / 2);
at.rotate(rotate);
at.shear(0, 1);
g2d.setTransform(at);
AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
alpha);
g2d.setComposite(ac);
g2d.drawString("Google VS Baidu", x, y + fm.getAscent());
}
public static void main(String[] args) throws Exception {
JFrame frame = new JFrame("Frame");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 400);
frame.getContentPane().add(new Test());
frame.setVisible(true);
}
}