- Explore o mundo Google em 2003. “Trabalho é difícil e você precisa descansar. Férias ensolaradas é somente um detalhe, mas onde começar? Com o Google existe um mundo a ser descoberto, ganhe tempo com os recursos disponíveis aos seus dedos.”
- Como fazer uma pesquisa melhor – dicas úteis.
- Especial ‘Dia dos Namorados’ 2001 – um aplicativo Java mostra um coração e escreve “I love you/Eu te amo” em diversos idiomas. Isso foi antes do Google começar a produzir logotipos para eventos especiais.
- 20 anos de Usenet – inclui menções a Microsoft, Sun, Cisco, Madonna, Britney Spears, Mac OSX e Google.
- Estatísticas sobre uso de elemento html
- Em 2003, Google indexava 3 bilhões de documentos. Agora, o Google tem mais de 24 milhões de documentos indexados. Veja também por que tamanho é importante.
- Google informa ranks #1 de busca por lealdade e satisfação (em 2000)
- Google Voice Search – busque no Google usando apenas sua voz através de uma simples chamada telefônica
- Site-flavored search – entre com a URL de algum site e o Google irá tentar cirar um perfil baseado no conteúdo
- AdSense para papel – Google tinha como alvo exibir AdSense em revistas
- Dilbert e o Google Doodle – o primeiro e último desenho do Dilbert no Google
- Britney Spears – correção de escrita – o banco de dados mostra uma gama de resultados de grafia errada que é corrigida pelo sistema do Google. No exemplo disponível, é exibido todas as forma de escrita errada em relação ao nome da cantora Britney Spears
- Google mostra estatísticas de 11 de setembro de 2001 – veja também condolências aos familiares pelo Google
- Google pode ajudar sua empresa fazer mais dinheiro – modelos promocionais para AdSense, AdWords e Froogle
- AdWords 2004 – uma apresentação sobre AdWords com imagens cinzas do Googleplex
- Librarian Center – uma newsletter com dicas sobre pesquisas para bibliotecas
- Esta página é usada para explicar o funcionamento do sistema do Google em relação a alguns resultados estranhos
- Procurando pelo Picasa? E sobre Urchin?
Arquivo da tag: java
Animation: bounce
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Checkbox;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Label;
import java.awt.Panel;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.awt.geom.GeneralPath;
import java.awt.geom.Rectangle2D;
import java.text.NumberFormat;
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Bouncer extends JPanel implements Runnable {
private boolean trucking = true;
private long[] previousTimes; // milliseconds
private int previousIndex;
private boolean previousFilled;
private double frameRate; // frames per second
private Image image;
public static void main(String[] args) {
final Bouncer bouncer = new Bouncer();
Frame f = new AnimationFrame(bouncer);
f.setFont(new Font("Serif", Font.PLAIN, 12));
f.setSize(200, 200);
Panel controls = new Panel();
controls.add(bouncer.createCheckbox("Anti.", Bouncer.ANTIALIASING));
controls.add(bouncer.createCheckbox("Trans.", Bouncer.TRANSFORM));
controls.add(bouncer.createCheckbox("Gradient", Bouncer.GRADIENT));
controls.add(bouncer.createCheckbox("Outline", Bouncer.OUTLINE));
controls.add(bouncer.createCheckbox("Dotted", Bouncer.DOTTED));
controls.add(bouncer.createCheckbox("Axes", Bouncer.AXES));
controls.add(bouncer.createCheckbox("Clip", Bouncer.CLIP));
f.add(controls, BorderLayout.NORTH);
f.setVisible(true);
}
// Tweakable variables
private boolean mAntialiasing, mGradient, mOutline;
private boolean mTransform, mDotted, mAxes, mClip;
// ...and the constants that represent them. See setSwitch().
public static final int ANTIALIASING = 0;
public static final int GRADIENT = 1;
public static final int OUTLINE = 2;
public static final int TRANSFORM = 3;
public static final int DOTTED = 4;
public static final int AXES = 5;
public static final int CLIP = 6;
private float[] mPoints;
private float[] mDeltas;
private float mTheta;
private int mN;
private Shape mClipShape;
public Bouncer() {
previousTimes = new long[128];
previousTimes[0] = System.currentTimeMillis();
previousIndex = 1;
previousFilled = false;
mN = 38;
mPoints = new float[mN];
mDeltas = new float[mN];
Random random = new Random();
for (int i = 0; i < mN; i++) {
mPoints[i] = random.nextFloat() * 500;
mDeltas[i] = random.nextFloat() * 3;
}
addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent ce) {
Dimension d = getSize();
for (int i = 0; i < mN; i++) {
int limit = ((i % 2) == 0) ? d.width : d.height;
if (mPoints[i] < 0)
mPoints[i] = 0;
else if (mPoints[i] >= limit)
mPoints[i] = limit - 1;
}
}
});
}
public void setSwitch(int item, boolean value) {
switch (item) {
case ANTIALIASING:
mAntialiasing = value;
break;
case GRADIENT:
mGradient = value;
break;
case OUTLINE:
mOutline = value;
break;
case TRANSFORM:
mTransform = value;
break;
case DOTTED:
mDotted = value;
break;
case AXES:
mAxes = value;
break;
case CLIP:
mClip = value;
break;
default:
break;
}
}
protected Checkbox createCheckbox(String label, final int item) {
Checkbox check = new Checkbox(label);
check.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent ie) {
setSwitch(item, (ie.getStateChange() == ie.SELECTED));
}
});
return check;
}
public void timeStep() {
Dimension d = getSize();
for (int i = 0; i < mN; i++) {
float value = mPoints[i] + mDeltas[i];
int limit = ((i % 2) == 0) ? d.width : d.height;
if (value < 0 || value > limit) {
mDeltas[i] = -mDeltas[i];
mPoints[i] += mDeltas[i];
} else
mPoints[i] = value;
}
mTheta += Math.PI / 192;
if (mTheta > (2 * Math.PI))
mTheta -= (2 * Math.PI);
}
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
setAntialiasing(g2);
setClip(g2);
setTransform(g2);
Shape shape = createShape();
setPaint(g2);
g2.fill(shape);
if (mOutline) {
setStroke(g2);
g2.setPaint(Color.blue);
g2.draw(shape);
}
drawAxes(g2);
}
protected void setAntialiasing(Graphics2D g2) {
if (mAntialiasing == false)
return;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
}
protected void setClip(Graphics2D g2) {
if (mClip == false)
return;
if (mClipShape == null) {
Dimension d = getSize();
FontRenderContext frc = g2.getFontRenderContext();
Font font = new Font("Serif", Font.PLAIN, 144);
String s = "Java Source and Support!";
GlyphVector gv = font.createGlyphVector(frc, s);
Rectangle2D bounds = font.getStringBounds(s, frc);
mClipShape = gv.getOutline(
(d.width - (float) bounds.getWidth()) / 2,
(d.height + (float) bounds.getHeight()) / 2);
}
g2.clip(mClipShape);
}
protected void setTransform(Graphics2D g2) {
if (mTransform == false)
return;
Dimension d = getSize();
g2.rotate(mTheta, d.width / 2, d.height / 2);
}
protected Shape createShape() {
GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD,
mPoints.length);
path.moveTo(mPoints[0], mPoints[1]);
for (int i = 2; i < mN; i += 6)
path.curveTo(mPoints[i], mPoints[i + 1], mPoints[i + 2],
mPoints[i + 3], mPoints[i + 4], mPoints[i + 5]);
path.closePath();
return path;
}
protected void setPaint(Graphics2D g2) {
if (mGradient) {
GradientPaint gp = new GradientPaint(0, 0, Color.yellow, 50, 25,
Color.red, true);
g2.setPaint(gp);
} else
g2.setPaint(Color.orange);
}
protected void setStroke(Graphics2D g2) {
if (mDotted == false)
return;
Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_ROUND, 10, new float[] { 4, 4 }, 0);
g2.setStroke(stroke);
}
protected void drawAxes(Graphics2D g2) {
if (mAxes == false)
return;
g2.setPaint(getForeground());
g2.setStroke(new BasicStroke());
Dimension d = getSize();
int side = 20;
int arrow = 4;
int w = d.width / 2, h = d.height / 2;
g2.drawLine(w - side, h, w + side, h);
g2.drawLine(w + side - arrow, h - arrow, w + side, h);
g2.drawLine(w, h - side, w, h + side);
g2.drawLine(w + arrow, h + side - arrow, w, h + side);
}
public void run() {
while (trucking) {
render();
timeStep();
calculateFrameRate();
}
}
protected void render() {
Graphics g = getGraphics();
if (g != null) {
Dimension d = getSize();
if (checkImage(d)) {
Graphics imageGraphics = image.getGraphics();
imageGraphics.setColor(getBackground());
imageGraphics.fillRect(0, 0, d.width, d.height);
imageGraphics.setColor(getForeground());
paint(imageGraphics);
g.drawImage(image, 0, 0, null);
imageGraphics.dispose();
}
g.dispose();
}
}
// Offscreen image.
protected boolean checkImage(Dimension d) {
if (d.width == 0 || d.height == 0)
return false;
if (image == null || image.getWidth(null) != d.width
|| image.getHeight(null) != d.height) {
image = createImage(d.width, d.height);
}
return true;
}
protected void calculateFrameRate() {
// Measure the frame rate
long now = System.currentTimeMillis();
int numberOfFrames = previousTimes.length;
double newRate;
// Use the more stable method if a history is available.
if (previousFilled)
newRate = (double) numberOfFrames
/ (double) (now - previousTimes[previousIndex]) * 1000.0;
else
newRate = 1000.0 / (double) (now - previousTimes[numberOfFrames - 1]);
firePropertyChange("frameRate", frameRate, newRate);
frameRate = newRate;
// Update the history.
previousTimes[previousIndex] = now;
previousIndex++;
if (previousIndex >= numberOfFrames) {
previousIndex = 0;
previousFilled = true;
}
}
public double getFrameRate() {
return frameRate;
}
// Property change support.
private transient AnimationFrame mRateListener;
public void setRateListener(AnimationFrame af) {
mRateListener = af;
}
public void firePropertyChange(String name, double oldValue, double newValue) {
mRateListener.rateChanged(newValue);
}
}
class AnimationFrame extends JFrame {
private Label mStatusLabel;
private NumberFormat mFormat;
public AnimationFrame(Bouncer ac) {
super();
setLayout(new BorderLayout());
add(ac, BorderLayout.CENTER);
add(mStatusLabel = new Label(), BorderLayout.SOUTH);
// Create a number formatter.
mFormat = NumberFormat.getInstance();
mFormat.setMaximumFractionDigits(1);
// Listen for the frame rate changes.
ac.setRateListener(this);
// Kick off the animation.
Thread t = new Thread(ac);
t.start();
}
public void rateChanged(double frameRate) {
mStatusLabel.setText(mFormat.format(frameRate) + " fps");
}
}
Bounce Thread
/**
* @version 1.20 1999-04-25
* @author Cay Horstmann
*/
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class BounceThread {
public static void main(String[] args) {
JFrame frame = new BounceThreadFrame();
frame.show();
}
}
class BounceThreadFrame extends JFrame {
public BounceThreadFrame() {
setSize(300, 200);
setTitle("Bounce");
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
Container contentPane = getContentPane();
canvas = new JPanel();
contentPane.add(canvas, "Center");
JPanel p = new JPanel();
addButton(p, "Start", new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Ball b = new Ball(canvas);
b.start();
}
});
addButton(p, "Close", new ActionListener() {
public void actionPerformed(ActionEvent evt) {
canvas.setVisible(false);
System.exit(0);
}
});
contentPane.add(p, "South");
}
public void addButton(Container c, String title, ActionListener a) {
JButton b = new JButton(title);
c.add(b);
b.addActionListener(a);
}
private JPanel canvas;
}
class Ball extends Thread {
public Ball(JPanel b) {
box = b;
}
public void draw() {
Graphics g = box.getGraphics();
g.fillOval(x, y, XSIZE, YSIZE);
g.dispose();
}
public void move() {
if (!box.isVisible())
return;
Graphics g = box.getGraphics();
g.setXORMode(box.getBackground());
g.fillOval(x, y, XSIZE, YSIZE);
x += dx;
y += dy;
Dimension d = box.getSize();
if (x < 0) {
x = 0;
dx = -dx;
}
if (x + XSIZE >= d.width) {
x = d.width - XSIZE;
dx = -dx;
}
if (y < 0) {
y = 0;
dy = -dy;
}
if (y + YSIZE >= d.height) {
y = d.height - YSIZE;
dy = -dy;
}
g.fillOval(x, y, XSIZE, YSIZE);
g.dispose();
}
public void run() {
try {
draw();
for (int i = 1; i <= 1000; i++) {
move();
sleep(5);
}
} catch (InterruptedException e) {
}
}
private JPanel box;
private static final int XSIZE = 10;
private static final int YSIZE = 10;
private int x = 0;
private int y = 0;
private int dx = 2;
private int dy = 2;
}
Como criar animações
import
java.applet.Applet;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class AppletAnimation extends Applet implements Runnable {
int frameNumber = -1;
int delay = 100;
Thread animatorThread;
boolean frozen = false;
public void init() {
String str;
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
if (frozen) {
frozen = false;
start();
} else {
frozen = true;
stop();
}
}
});
}
public void start() {
if (!frozen) {
if (animatorThread == null) {
animatorThread = new Thread(this);
}
animatorThread.start();
}
}
public void stop() {
animatorThread = null;
}
public void run() {
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
long startTime = System.currentTimeMillis();
Thread currentThread = Thread.currentThread();
while (currentThread == animatorThread) {
frameNumber++;
repaint();
try {
startTime += delay;
Thread.sleep(100);
} catch (InterruptedException e) {
break;
}
}
}
public void paint(Graphics g) {
g.drawString("Frame " + frameNumber, 0, 30);
}
}
Como criar animações: Paint e Thread
import
java.awt.Color;
import java.awt.Graphics;
import java.awt.Insets;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JFrame;
public class Animate extends JFrame {
private static int DELAY = 100;
Insets insets;
Color colors[] = { Color.RED, Color.ORANGE, Color.YELLOW, Color.GREEN,
Color.BLUE, Color.MAGENTA };
public void paint(Graphics g) {
super.paint(g);
if (insets == null) {
insets = getInsets();
}
// Calculate each time in case of resize
int x = insets.left;
int y = insets.top;
int width = getWidth() - insets.left - insets.right;
int height = getHeight() - insets.top - insets.bottom;
int start = 0;
int steps = colors.length;
int stepSize = 360 / steps;
synchronized (colors) {
for (int i = 0; i < steps; i++) {
g.setColor(colors[i]);
g.fillArc(x, y, width, height, start, stepSize);
start += stepSize;
}
}
}
public void go() {
TimerTask task = new TimerTask() {
public void run() {
Color c = colors[0];
synchronized (colors) {
System.arraycopy(colors, 1, colors, 0, colors.length - 1);
colors[colors.length - 1] = c;
}
repaint();
}
};
Timer timer = new Timer();
timer.schedule(task, 0, DELAY);
}
public static void main(String args[]) {
Animate f = new Animate();
f.setSize(200, 200);
f.show();
f.go();
}
}
Noise Image
import
java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
import java.awt.image.IndexColorModel;
import java.awt.image.Raster;
import java.awt.image.WritableRaster;
import java.util.Random;
import javax.swing.JComponent;
import javax.swing.JFrame;
public class StaticGenerator extends JComponent implements Runnable {
byte[] data;
BufferedImage image;
Random random;
public void initialize() {
int w = getSize().width, h = getSize().height;
int length = ((w + 7) * h) / 8;
data = new byte[length];
DataBuffer db = new DataBufferByte(data, length);
WritableRaster wr = Raster.createPackedRaster(db, w, h, 1, null);
ColorModel cm = new IndexColorModel(1, 2, new byte[] { (byte) 0, (byte) 255 }, new byte[] {
(byte) 0, (byte) 255 }, new byte[] { (byte) 0, (byte) 255 });
image = new BufferedImage(cm, wr, false, null);
random = new Random();
new Thread(this).start();
}
public void run() {
while (true) {
random.nextBytes(data);
repaint();
try {
Thread.sleep(1000 / 24);
} catch (InterruptedException e) { /* die */
}
}
}
public void paint(Graphics g) {
if (image == null)
initialize();
g.drawImage(image, 0, 0, this);
}
public static void main(String[] args) {
JFrame f = new JFrame();
f.add(new StaticGenerator());
f.setSize(300, 300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
Hypnosis animation
import
java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.geom.GeneralPath;
import javax.swing.JComponent;
import javax.swing.JFrame;
public class Hypnosis1 extends JComponent implements Runnable {
private int[] coordinates;
private int[] deltas;
private Paint paint;
public Hypnosis1(int numberOfSegments) {
int numberOfCoordinates = numberOfSegments * 4 + 2;
coordinates = new int[numberOfCoordinates];
deltas = new int[numberOfCoordinates];
for (int i = 0; i < numberOfCoordinates; i++) {
coordinates[i] = (int) (Math.random() * 300);
deltas[i] = (int) (Math.random() * 4 + 3);
if (deltas[i] > 4)
deltas[i] = -(deltas[i] - 3);
}
paint = new GradientPaint(0, 0, Color.blue, 20, 10, Color.red, true);
Thread t = new Thread(this);
t.start();
}
public void run() {
try {
while (true) {
timeStep();
repaint();
Thread.sleep(1000 / 24);
}
} catch (InterruptedException ie) {
}
}
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Shape s = createShape();
g2.setPaint(paint);
g2.fill(s);
g2.setPaint(Color.white);
g2.draw(s);
}
private void timeStep() {
Dimension d = getSize();
if (d.width == 0 || d.height == 0)
return;
for (int i = 0; i < coordinates.length; i++) {
coordinates[i] += deltas[i];
int limit = (i % 2 == 0) ? d.width : d.height;
if (coordinates[i] < 0) {
coordinates[i] = 0;
deltas[i] = -deltas[i];
} else if (coordinates[i] > limit) {
coordinates[i] = limit - 1;
deltas[i] = -deltas[i];
}
}
}
private Shape createShape() {
GeneralPath path = new GeneralPath();
path.moveTo(coordinates[0], coordinates[1]);
for (int i = 2; i < coordinates.length; i += 4)
path.quadTo(coordinates[i], coordinates[i + 1], coordinates[i + 2], coordinates[i + 3]);
path.closePath();
return path;
}
public static void main(String[] args) {
JFrame f = new JFrame("Hypnosis");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(new Hypnosis1(4));
f.setSize(300, 300);
f.setVisible(true);
}
}
Font size animation
import
java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;
public class FontSizeAnimation extends JPanel implements ActionListener {
Timer timer;
int x = 1;
float alpha = 1;
public FontSizeAnimation() {
timer = new Timer(8, this);
timer.setInitialDelay(190);
timer.start();
}
public void paint(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
Font font = new Font("Dialog", Font.PLAIN, x);
g2d.setFont(font);
FontMetrics fm = g2d.getFontMetrics();
String s = "Java";
int w = (int) getSize().getWidth();
int h = (int) getSize().getHeight();
int stringWidth = fm.stringWidth(s);
g2d.drawString(s, (w - stringWidth) / 2, h / 2);
}
public static void main(String[] args) {
JFrame frame = new JFrame("FontSizeAnimation");
frame.add(new FontSizeAnimation());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 300);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
x += 1;
alpha -= 0.0001;
repaint();
}
}
Fade out de uma imagem: a imagem vai ficando transparente gradualmente até que esteja completamente invisível
import
java.awt.AlphaComposite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;
public class FadeOutImage extends JPanel implements ActionListener {
Image myImage = new ImageIcon("a.jpg").getImage();
Timer timer = new Timer(20, this);
private float alpha = 1f;
public FadeOutImage() {
timer.start();
}
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
g2d.drawImage(myImage, 10, 10, null);
}
public void actionPerformed(ActionEvent e) {
alpha += -0.01f;
if (alpha <= 0) {
alpha = 0;
timer.stop();
}
repaint();
}
public static void main(String[] args) {
JFrame frame = new JFrame("Fade out");
frame.add(new FadeOutImage());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 250);
frame.setVisible(true);
}
}
A rotating and scaling rectangle
import
java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;
public class SwingTimerBasedAnimationScaleRotate extends JPanel implements ActionListener {
Timer timer;
private double angle = 0;
private double scale = 1;
private double delta = 0.01;
Rectangle.Float r = new Rectangle.Float(20, 20, 200, 200);
public SwingTimerBasedAnimationScaleRotate() {
timer = new Timer(10, this);
timer.start();
}
public void paint(Graphics g) {
int h = getHeight();
int w = getWidth();
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2d.translate(w / 2, h / 2);
g2d.rotate(angle);
g2d.scale(scale, scale);
g2d.fill(r);
}
public static void main(String[] args) {
JFrame frame = new JFrame("Moving star");
frame.add(new SwingTimerBasedAnimationScaleRotate());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(420, 250);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (scale < 0.01) {
delta = -delta;
} else if (scale > 0.99) {
delta = -delta;
}
scale += delta;
angle += 0.01;
repaint();
}
}