大数据学习乌龟制作第二天
乌龟制作
代码1
package com.nf.www;
import javax.swing.JFrame;
public class TutlePro {
public static void mian (String[] args){
JFrame frame =new JFrame();
frame.setTitle(“忍者神龟”);
frame.setSize(1400,800);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
TJPanel tj= new TJPanel();
frame.add(tj);
frame.setVisible(true);
}}
代码2
package com.nf.www;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
import javax.swing.colorchooser.ColorChooserComponentFactory;
public class TJPanel extends JPanel{
//乌龟的初始位置
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);
*/
}
}