import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;
public class Main {
Timer timer;
Mill mill;
JFrame frame;
int t=0;
public Main(){
frame=new JFrame();
mill=new Mill();
frame.getContentPane().add(mill);
frame.setSize(new java.awt.Dimension(700,700));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mill.setPreferredSize(new java.awt.Dimension(800,700));
frame.setVisible(true);
frame.pack();
timer=new Timer(100,new ActionListener() {
public void actionPerformed(ActionEvent e) {
t++;
mill.repaint();
}
});
timer.start();
}
public static void main(String[] args) {
new Main();
}
BufferedImage buff=new BufferedImage(1,1,BufferedImage.TYPE_INT_RGB);
class Mill extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g3=(Graphics2D)g;
{//.. paint only
if( buff==null|| buff.getWidth()!=mill.getWidth() ||
buff.getHeight()!=mill.getHeight()
){
buff=new BufferedImage(mill.getWidth(),mill.getHeight(),BufferedImage.TYPE_INT_RGB);
}
Graphics2D g2 = (Graphics2D) buff.createGraphics();
g2.setColor(new Color(0,0,100));
g2.fillRect( 0,0,600,600);
g2.setColor(new Color(0,0,200));
g2.fillRect( 0,0,500,500);
g2.setColor(new Color(0,0,250));
g2.fillRect( 0,0,400,400);
}
g3.drawImage( buff,0,0,buff.getWidth(),buff.getHeight(),this);
}
}
}