Advertisement
mikhail_dvorkin

PaintingApplet

Mar 15th, 2017
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.awt.image.BufferedImage;
  4. import javax.swing.*;
  5.  
  6. @SuppressWarnings("serial")
  7. public class PaintingApplet extends JApplet implements ActionListener {
  8.     int x = 10;
  9.    
  10.     Timer timer = new Timer(1, this);
  11.    
  12.     public void init() {
  13.         timer.start();
  14.     }
  15.    
  16.     @Override
  17.     public void paint(Graphics g) {
  18.         Image image = drawFrame();
  19.         g.drawImage(image, 0, 0, null);
  20.     }
  21.  
  22.     Image drawFrame() {
  23.         BufferedImage image = new BufferedImage(
  24.                 this.getWidth(), this.getHeight(),
  25.                 BufferedImage.TYPE_INT_RGB);
  26.         Graphics g = image.getGraphics();
  27.         g.drawLine(x + 10, 20, x + 100, 100);
  28.         g.setColor(Color.MAGENTA);
  29.         g.drawOval(0, 0, 100, 200);
  30.         g.setColor(new Color(255, 50, 0));
  31.         g.drawRoundRect(10, 10, 90, 190, 20, 20);
  32.         g.fillArc(x, x, 100, 200, 0, 60);
  33.         g.setColor(Color.GRAY);
  34.         return image;
  35.     }
  36.  
  37.     @Override
  38.     public void actionPerformed(ActionEvent e) {
  39.         x += 1;
  40.         x %= 400;
  41.         repaint();
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement