Advertisement
far_light

Panel

Mar 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. package com.company;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.*;
  6.  
  7. public class Panel extends JPanel {
  8.     private  int value = 0;
  9.  
  10.     public  Panel() {
  11.         setLayout(null);
  12.  
  13.         Timer timer = new Timer(200, new ActionListener() {
  14.             @Override
  15.             public void actionPerformed(ActionEvent e) {
  16.                 value++;
  17.                 if (value == 256)
  18.                     value = 0;
  19.                 repaint();
  20.             }
  21.         });
  22.         timer.start();
  23.     }
  24.  
  25.      public void paintComponent(Graphics graphics) {
  26.         super.paintComponent(graphics);
  27.  
  28.         for (int i = 0; i <= 255; i++) {
  29.             graphics.setColor(new Color(0, (i * value) % 255, 0));
  30.             graphics.drawRect(250 - i / 2, 220 - i / 2, i, i);
  31.         }
  32.      }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement