Home > Back-end >  Save the children!
Save the children!

Time:09-21

For help, Java exactly how to make a smooth animation,
Stick down the source code, is a little confusing,
Key in the run method, I this flag values change often is not normal, originally set minus one at a time, but increase the thread to sleep later, don't know why will decrease much, cause the picture make a mistake, and now run for a while, the picture is wrong, the pole is missing, the red flag is not stable, also flash picture, have without bosses solutions under
o...
Package hw_draw;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


Public class drawhouse extends JFrame implements ActionListener//, Runnable
{
Private JButton flagbegin_button;//the flag-raising start
Private JButton flagcut_button;//the flag-raising interrupt
Private JButton sunbegin_button;//the sun began to
Private JButton suncut_button;//the sun break
Private Canvas Canvas;
Thread moveingthr;
Public drawhouse ()
{
Super (" graphics ");
Dimension dim=this. GetToolkit (.) getScreenSize ();
Enclosing setBounds (dim. Width/8, dim. The height/8, dim. The width/4 * 3, dim. The height/4 * 3);
Enclosing setDefaultCloseOperation (EXIT_ON_CLOSE);//close button by default

JPanel CMD=new JPanel ();
CMD. SetBackground (new Color (0 x277fd2b5, true));
Enclosing flagbegin_button=new JButton (" flag ");
Flag raising the enclosing flagcut_button=new JButton (" ");
Enclosing sunbegin_button=new JButton (" the sun ");
Enclosing suncut_button=new JButton (" interruption of the sun ");

This. Flagbegin_button. AddActionListener (this);
This. Flagcut_button. AddActionListener (this);
This. Sunbegin_button. AddActionListener (this);
This. Suncut_button. AddActionListener (this);

CMD. The add (flagbegin_button);
CMD. The add (flagcut_button);
CMD. The add (sunbegin_button);
CMD. The add (suncut_button);
This. The add (CMD, "North");

//this. Moveingthr=new Thread (this, "animation");

This. Canvas=new HouseCanvas ();
This. Canvas. SetBackground (new Color (0 x277fd2b5, true));
Enclosing getContentPane (). The add (enclosing canvas, "Center");
Enclosing setVisible (true);

}
Public void actionPerformed (an ActionEvent e)
{
//if (um participant etSource ()==flagbegin_button)
}

Public void the run ()
{

}

Private static class HouseCanvas extends Canvas implements Runnable
{
Private Thread th001;
Public void paint (Graphics Graphics)
{
Super. Paint (graphics);
Color purewhite=new Color (0 XFFFFFFFF, true);
Color greengrey=new Color (207222215);
Graphics. SetColor (new Color (0 x08b7fc));
,0,1800,330 graphics. FillRect (0);
Graphics. SetColor (greengrey);
Graphics. FillRect (350, 300, 220, 180);//house subject rectangle
Graphics. FillRect (330480260);//house base

Graphics. SetColor (new Color (146187173));
Graphics. FillRect (350380220100);//house wall below
Graphics. SetColor (new Color (117156143));
Graphics. FillRect,90,150 (450330);//the most outer frame
Graphics. SetColor (purewhite);
Graphics. FillRect,70,140 (460340);//the middle layer frame
Graphics. SetColor (new Color (0 x40b6b6));
Graphics. FillRect,60,135 (465345);//the inner frame
Graphics. SetColor (purewhite);
Graphics. FillOval,10,10 (505410);//the handle

Graphics. SetColor (new Color (117156143));
Graphics. FillRoundRect,20,15,2,2 (350340);//on the left side of the stone brick
Graphics. FillRoundRect,20,15,2,2 (430360);//door stone brick
Graphics. SetColor (new Color (0 x4a2c8e8e, true));
Graphics. FillRoundRect,20,15,2,2 (500315);//on the door square brick

Graphics. SetColor (new Color (117156143));
Graphics. FillRoundRect,60,60,4,4 (365360);//dark frame
Graphics. SetColor (purewhite);
Graphics. FillRoundRect,50,50,2,2 (370365);//white window frame
Graphics. SetColor (new Color (117156143));
Graphics. FillRoundRect,40,40,2,2 (375370);//window
Graphics. SetColor (purewhite);
Graphics. FillRoundRect,50,5,1,1 (370387);//window
Graphics. FillRoundRect,5,50,1,1 (392365);//window

Int [] x={340580560360};
Int [] y={300300220220};
Graphics. SetColor (new Color (0 xff9a7c));
Graphics. FillPolygon (x, y, 4);//roof

Graphics. SetColor (new Color (0 x759c8f));
Graphics. FillRoundRect,40,60,2,2 (385180);
Graphics. SetColor (purewhite);
Graphics. FillOval,30,15 (410155);
Graphics. FillOval,40,20 (430135);//chimney

Graphics. SetColor (new Color (0 xff957c3e, true));
Graphics. FillRoundRect,40,180,2,2 (210300);
Graphics. SetColor (new Color (0 x83f51f));
Int [] xtree={130330240300240280230180220160220130};
Int [] ytree={300300260260220220190220220260260300};
Graphics. FillPolygon (xtree ytree, 12);//tree

Graphics. SetColor (purewhite);
Graphics. FillOval,50,40 (600135);
Graphics. FillOval,40,50 (630130);
Graphics. FillOval,40,50 (660130);
Graphics. FillOval,35,50 (648107);
Graphics. FillOval,40,30 (675140);
Graphics. FillOval,50,40 (610110);
Graphics. FillOval,40,40 (675110);//the clouds

Graphics. SetColor (new Color (0 xeeffbf00, true));
Graphics. FillOval,80,80 (960160);
Int [] x1sun={1001102, 6103, 0104, 2105, 7106, 6105, 6104, 5102, 0100, 3987968949948941946957981};
Int [] y1sun={255259245225203190171148140136136151171187206225244255};
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related