When drawing images using java, the image needs to be cached for speed. Write a sample code for your reference.
Import java. awt. Color;
Import java. awt. Container;
Import java. awt. Graphics;
Import java. awt. Graphics2D;
Import java. awt. Image;
Import java. awt. Transparency;
Import java. awt. event. WindowAdapter;
Import java. awt. event. Javaswevent;
Import java. awt. image. BufferedImage;
Import javax. swing. JFrame;
Import javax. swing. JPanel;
Class MyPanel extends JPanel {
Private int px = 400;
Private Image newImage = null;
Public MyPanel (){
Super ();
This. setSize (400,400 );
Final MyPanel t = this;
// Draw a graph by the internal thread. In a specific application, it is generally controlled by the external
New Thread (){
Public void run (){
Try {
While (true ){
T. addPX ();
T. repaint ();
This. sleep (10 );
}
} Catch (Exception e ){
E. printStackTrace ();
}
}