旋转 图片

这个旋转的太极图是自己培训时老师所写。

由于长时间没有写博客,而且这个短小但很有效果的旋转 太极图不写出来感觉有点可惜。

一直都喜欢借用 类库写些篇幅不长但是功能很强的代码,这个可以说很符合我的意愿。

下面是代码:

package day2;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class CopyOfDemo2 {
  public static void main(String[] args){
	  JFrame win = new JFrame();
	  win.setSize(400, 400);
	  Pane p = new Pane();
	  Thread t = new Thread(p);
	  t.start();
	  win.add(p);
	  win.setVisible(true);
	  
	  
  }
}
class Pane extends JPanel implements Runnable{
	int x ;
	public Pane(){
		x =0;
	}
	public void paint(Graphics g){
		super.paint(g);
		
		Graphics2D g2 = (Graphics2D)g;
g2.rotate(x, 155, 155);
g2.setColor(Color.BLACK);
g2.fillArc(100, 100, 100, 100, 90, 180);
g2.fillOval(125, 100, 50, 50);
g2.setColor(Color.WHITE);
g2.fillArc(100, 100, 100, 100, 90, -180);
g2.setColor(Color.BLACK);
g2.fillOval(125, 100, 50, 50);
g2.setColor(Color.WHITE);
g2.fillOval(125, 150, 50, 50);	
g2.fillOval(140, 120, 20, 20);
g2.setColor(Color.BLACK);
g2.fillOval(140, 165, 20, 20);

	}
	public void run(){
		while(true){
			x++;
			try {
				Thread.sleep(500);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			repaint();
		}
	}
}
希望大家喜欢!



猜你喜欢

转载自blog.csdn.net/libingbojava/article/details/78724442