Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import java.awt.image.BufferedImage;
- import javax.swing.*;
- @SuppressWarnings("serial")
- public class PaintingApplet extends JApplet implements ActionListener {
- int x = 10;
- Timer timer = new Timer(1, this);
- public void init() {
- timer.start();
- }
- @Override
- public void paint(Graphics g) {
- Image image = drawFrame();
- g.drawImage(image, 0, 0, null);
- }
- Image drawFrame() {
- BufferedImage image = new BufferedImage(
- this.getWidth(), this.getHeight(),
- BufferedImage.TYPE_INT_RGB);
- Graphics g = image.getGraphics();
- g.drawLine(x + 10, 20, x + 100, 100);
- g.setColor(Color.MAGENTA);
- g.drawOval(0, 0, 100, 200);
- g.setColor(new Color(255, 50, 0));
- g.drawRoundRect(10, 10, 90, 190, 20, 20);
- g.fillArc(x, x, 100, 200, 0, 60);
- g.setColor(Color.GRAY);
- return image;
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- x += 1;
- x %= 400;
- repaint();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement