1 Packagedemo;2 3 ImportJava.awt.Color;4 ImportJava.awt.Graphics;5 6 ImportJavax.swing.JFrame;7 ImportJavax.swing.JPanel;8 9 /**Ten * Java Dynamictaichi (collation) One * A * 2016-1-2 Shenzhen Nanshan Ping Shan village Zengjianfeng - */ - the Public classDynamictaichiextendsjpanel{ - Private Static Final LongSerialversionuid = 1L; - /* - * All data are changed proportionally according to CenterX, so + * If you want to change the size of the panel, you can modify the CenterX value directly. - */ + Static intCenterX = 600/2; A Static intCenterY =CenterX; at Static intCicle =CenterX; - Static intAngle = 0; - - PublicDynamictaichi () { - start (); - } in Private voidstart () { - NewThread (NewRunnable () { to + @Override - Public voidrun () { the while(true) { * Try { $angle++;Panax NotoginsengThread.Sleep (10); - repaint (); the}Catch(Exception e) { + e.printstacktrace (); A } the } + - } $ }). Start (); $ } - @Override - Public voidPaint (Graphics graphics) { the Super. Paint (graphics); - This. SetBackground (color.red);Wuyi Graphics.setcolor (color.white); theGraphics.fillarc (CENTERX-CICLE/2, CENTERY-CICLE/2, cicle, cicle, Angle, 180); - Graphics.setcolor (color.black); WuGraphics.fillarc (CENTERX-CICLE/2, CENTERY-CICLE/2, Cicle, Cicle, 180+angle, 180); -Graphics.fillarc (centerx+ (int) (Cicle/2/2* (Math.Cos (angle*math.pi/180)))-CICLE/2/2, centery-(int) (Cicle/2/2* (Math.sin (angle*math.pi/180))-CICLE/2/2, CICLE/2, CICLE/2, 0, 360); About Graphics.setcolor (color.white); $Graphics.fillarc (centerx+ (int) (Cicle/2/2* (Math.Cos ((angle+180) *math.pi/180))-CICLE/2/2, centery-(int) (Cicle/2/2* (Math.sin ((angle+180) *math.pi/180))-CICLE/2/2, CICLE/2, CICLE/2, 0, 360); - Graphics.setcolor (color.black); -Graphics.fillarc (centerx+ (int) (Cicle/2/2* (Math.Cos ((angle+180) *math.pi/180))-CICLE/2/2/2, centery-(int) (Cicle/2/2* (Math.sin ((angle+180) *math.pi/180))-CICLE/2/2/2, CICLE/2/2, CICLE/2/2, 0, 360); - Graphics.setcolor (color.white); AGraphics.fillarc (centerx+ (int) (Cicle/2/2* (Math.Cos (angle*math.pi/180)))-CICLE/2/2/2, centery-(int) (Cicle/2/2* (Math.sin (angle*math.pi/180))-CICLE/2/2/2, CICLE/2/2, CICLE/2/2, 0, 360); + } the - Public Static voidMain (string[] args) { $JFrame JFrame =NewJFrame (); theJframe.settitle ("Dynamictaichi"); theJframe.setsize (centerx*2, centery*2); the jframe.setdefaultcloseoperation (jframe.exit_on_close); theJframe.setlocationrelativeto (NULL); - inDynamictaichi JPanel =NewDynamictaichi (); the Jframe.add (jPanel); the AboutJframe.setvisible (true); the } the}
Java Dynamictaichi (Collation)