day2.2 - Wayne53777/Java- GitHub Wiki

画王八 package cn.zwz.day02;

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

import javax.swing.JPanel;

@SuppressWarnings("serial") public class TJPanel extends JPanel{ //@Override /*public void paint(Graphics g) { // TODO Auto-generated method stub super.paint(g); //给画笔设置颜色 g.setColor(Color.red); //画矩形 g.drawRect(20, 150, 400, 600); //画实心 g.fillRect(120, 200, 160, 80); //画圆或椭圆 g.setColor(Color.blue); g.drawOval(40, 300, 100, 100); g.fillOval(30, 450, 200, 100); //奥迪车标 g.drawOval(40, 600, 30, 30); g.drawOval(60, 600, 30, 30); g.drawOval(80, 600, 30, 30); g.drawOval(100, 600, 30, 30); //画线段 g.drawLine(80, 80, 200, 200);

}

}*/

//乌龟的初始位置 int x=300; int y=200; //脚的初始位置 int k1=300,t1=200; int k2=300,t2=200; int k3=300,t3=200; int k4=300,t4=200;

@Override public void paint(Graphics g) { //alt+/ 快捷 // TODO Auto-generated method stub super.paint(g);

//加头
g.setColor(Color.green);
g.fillOval(x, y, 70, 100);
//加眼睛
g.setColor(Color.black);
g.fillOval(x+10, y+30, 10, 20);
g.fillOval(x+50, y+30, 10, 20);

//加舌头
g.setColor(Color.red);
g.fillOval(x+30 ,y-20, 10, 30);

//画脚
//左上
g.setColor(Color.green);
g.fillOval(k1-85, t1+76, 60,70);
//右上
g.setColor(Color.green);
g.fillOval(k2+85, t2+76, 60,70);
//左下
g.setColor(Color.green);
g.fillOval(k3-85, t3+235, 60,70);
//右下
g.setColor(Color.green);
g.fillOval(k4+85, t3+235, 60,70);
//加乌龟壳
g.setColor(Color.orange);
g.fillOval(x-66, y+66, 200, 230);

/* //给画笔设置颜色 g.setColor(Color.red); //画矩形 g.drawRect(30, 100, 400, 600); //画实心 g.fillRect(120, 200, 160, 80); //画圆或椭圆 g.setColor(Color.blue); g.drawOval(40, 300, 100, 100); g.fillOval(30, 450, 200, 100); //奥迪车标 g.drawOval(40, 600, 30, 30); g.drawOval(60, 600, 30, 30); g.drawOval(80, 600, 30, 30); g.drawOval(100, 600, 30, 30); //画线段 g.drawLine(20, 50, 400, 800);

*/

}

}