学以致用——Java源码——海龟绘图语言图形界面版(Turtle Graphics)

程序功能:

以图形界面的方式提供海龟绘图功能。

运行示例:

 

源码:

1. 实体类

package exercises.ch13graphicsandjava2d;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

//by pandenghuang@163.com
/*使用本程序绘图的小技巧:
1. 使用Excel辅助图形设计(帮助获取正确的指令)
2. 推荐的绘图顺序:向前移动前,先确定正确的前进方向,然后再设置画笔状态(抬起或落下)
3. 如果画板(棋盘)上某个位置为空,则应该在离开该位置向前移动到其他位置前,将画笔设置为抬起(输入指令1)。反之亦反。
*/ 
/**
 * 13.23 (Turtle Graphics) Modify your solution to Exercise 7.21—Turtle
 * Graphics—to add a graphical user interface using JTextFields and JButtons.
 * Draw lines rather than asterisks (*). When the turtle graphics program
 * specifies a move, translate the number of positions into a number of pixels
 * on the screen by multiplying the number of positions by 10 (or any value you
 * choose). Implement the drawing with Java 2D API features.
 */

public class TurtleGraphicsJPanel extends JPanel {
	
	private int pace=5;
	private int[][] positions = new int[20][20];
	private boolean penLocation;	//画笔位置(抬起或落下,默认为抬起)
	private String currentDirection; //当前朝向
	private boolean moveLeft,moveRight,moveDownwards,moveUpwards; 	//画笔移动方向(东、南、西、北)
	private int instruction;	//用户输入的单条指令
	private JLabel programDesc;	//程序使用说明
	private JLabel drawingStatus;	//画图状态(随指令运行而动态输出)
	private JLabel instructionJLabel;
	private JTextField instructionJTextField;
	private JLabel paceJLabel;
	private JTextField paceJTextField;
	private JPanel instructionSubJPanel;	//指令子面板(封装指令相关控件)
	private JPanel instructionJPanel;	//指令面板(封装绘图区以外的控件)
	private int hOffset;	//绘图区横向偏移
	private int vOffset;	//绘图区纵向偏移
	private int row;			//海龟在数组中的列标
	private int column;			//海龟在数组中的行标
	private int gridSize = 20;	//设置网格大小

	public TurtleGraphicsJPanel() {
		moveRight = true;		//初始朝向为向右
		currentDirection = "东";	//初始朝向为东

		this.setLayout(new GridLayout(1,2,5,10));
		


		programDesc = new JLabel("<html><body><h3>"
				+ "<font color=\"#0000FF\">请按照以下说明输入绘图指令:</font></h3><br>"
	     		+ "<font color=\"#090\">1:抬起画笔<br>"
	     		+ "2:落下画笔<br>"
	     		+ "3:右转<br>"
	     		+ "4:左转<br>"
	     		+ "5:画笔向前移动n步(第一次移动时默认为向右移动,n为自定义)<br>"
	     		+ "6:绘制图形<br>"
	     		+ "7:擦除图形<br>"
	     		+ "9:退出程序<br></font></body></html>");
		
		drawingStatus = new JLabel();
		
		instructionJLabel = new JLabel("指令:");
		setInstructionJTextField(new JTextField(5));

		
		paceJLabel = new JLabel("移动步数:");
		setPaceJTextField(new JTextField(8));
		getPaceJTextField().setEditable(false);

		
		instructionSubJPanel = new JPanel();
		instructionSubJPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
		instructionSubJPanel.add(instructionJLabel);
		instructionSubJPanel.add(getInstructionJTextField());
		instructionSubJPanel.add(paceJLabel);
		instructionSubJPanel.add(getPaceJTextField());
		
		instructionJPanel = new JPanel();
		instructionJPanel.setLayout(new GridLayout(3,1,10,10));
		instructionJPanel.add(programDesc);
		drawingStatus.setText(String.format("当前位置:【%d,%d】,当前朝向:%s",
				 row+1, column+1, currentDirection));
		instructionJPanel.add(instructionSubJPanel);
		instructionJPanel.add(drawingStatus);
		this.add(instructionJPanel, BorderLayout.NORTH);

		
		//监听指令文本框
	 	getInstructionJTextField().addActionListener(new ActionListener() {	//监听文本框,设置绘图指令
			@Override
			public void actionPerformed(ActionEvent e) {
			     
//				 if (e.getSource()==instructionJTextField) {
			     instruction =Integer.parseInt(getInstructionJTextField().getText());
				 if (instruction == 5) {
					 getPaceJTextField().setEditable(true);
					 getPaceJTextField().requestFocusInWindow();	//让步数输入框获取焦点
					 getPaceJTextField().selectAll();      	   //默认选中,方便用户直接输入	
					 drawingStatus.setText(String.format("请输入移动步数:"));
				 }
				 else {
					 turtleBehaviour(instruction);
					 getInstructionJTextField().selectAll();      	   //默认选中,方便用户直接输入
					 getPaceJTextField().setEditable(false);
					 }
//			 }
			}
		  });	
	 	
	 	//监听移动步数文本框
		getPaceJTextField().addActionListener(new ActionListener() {	
			@Override
			public void actionPerformed(ActionEvent e) {
//			if (e.getSource()==paceJTextField) {	
				 pace =Integer.parseInt(getPaceJTextField().getText());
				 getInstructionJTextField().requestFocusInWindow();	//让指令输入框获取焦点
				 getInstructionJTextField().selectAll();      	   //默认选中,方便用户直接输入
				 turtleBehaviour(instruction);	//如果指令是5,先设置步长,再执行前移动作
			 }
//		  }
			
	});
		
		
		drawHuang();	//画板初始化为“黄”字
		drawHong();		//画板初始化为“鸿”字


	}
 
 public void paint(Graphics g)
 {   

     super.paint(g);
     Graphics2D g2d = (Graphics2D) g;
	 int width = getWidth(); // total width   
	 int height = getHeight(); // total height
	 hOffset = width*1/2;
	 vOffset = height*1/5;

	g2d.setColor(Color.blue);
	for (int i=0;i<20;i++)
    {	
	    g2d.drawString(""+(i+1), i*gridSize+hOffset+6, vOffset-10);	//打印绘图区列标
	    }
	for (int i=0;i<20;i++)
    {	
	    g2d.drawString(""+(i+1), hOffset-17, i*gridSize+vOffset+14);	//打印绘图区行标
	    }
    for (int i=0;i<20;i++)	//打印绘图区内容
    {
	    for (int j=0;j<20;j++) {
	    if (positions[i][j]!=0) {	
		    g2d.fillRect(j*gridSize+hOffset, i*gridSize+vOffset, gridSize, gridSize);
	    		}
	    else
	    	g2d.drawRect(j*gridSize+hOffset, i*gridSize+vOffset, gridSize, gridSize);
	    	}
    }
    
}
 

 
 public void turtleBehaviour(int argument)
 {
     switch (argument)
     {
     case 1:	//抬起画笔
         penLocation=false;
         drawingStatus.setText(String.format("画笔已抬起。当前位置:【%d,%d】,当前朝向:%s" ,
        		 row+1, column+1, currentDirection));
         repaint();
         break;
     case 2:	//落下画笔
         penLocation=true;
         drawingStatus.setText(String.format("画笔已落下。当前位置:【%d,%d】,当前朝向:%s"
         		,row+1, column+1, currentDirection));
         repaint();
         break;
     case 3:// 右转
         if (moveRight)  //如果当前移动方向是右移,则右转向后移动方向变为向下移动
         {
             moveDownwards=true;	//向下移动为true
             moveLeft=moveRight=moveUpwards=false;	//其他移动方向为false
             currentDirection="南";
         }
         else if(moveLeft)	//如果当前移动方向是左移,则右转向后移动方向变为向上移动
         {
             moveUpwards=true;
             moveLeft=moveRight=moveDownwards=false;
             currentDirection="北";
         }
         else if(moveUpwards)	//如果当前移动方向是上移,则右转向后移动方向变为向右移动
         {
            moveRight=true;
            moveLeft=moveUpwards=moveDownwards=false;
            currentDirection="东";
         }
         else if(moveDownwards)	//如果当前移动方向是下移,则右转向后移动方向变为向左移动
         {
             moveLeft=true;
             moveUpwards=moveRight=moveDownwards=false;
             currentDirection="西";
         }
         drawingStatus.setText(String.format("朝向已更改为:%s%n, 当前位置:【%d,%d】",
        		 currentDirection, row+1, column+1));
         repaint();
         break;
     case 4:// 左转
         if (moveRight)
         {
             moveUpwards=true;
             moveLeft=moveRight=moveDownwards=false;
             currentDirection="北";
         }
         else if(moveLeft)
         {
             moveDownwards=true;
             moveLeft=moveRight=moveUpwards=false;
             currentDirection="南";
             
         }
         else if(moveUpwards)
       {
             moveLeft=true;
             moveRight=moveUpwards=moveDownwards=false;
             currentDirection="西";
         }
         else if(moveDownwards)
         {
             moveRight=true;
             moveUpwards=moveLeft=moveDownwards=false;
             currentDirection="东";
         }
         drawingStatus.setText(String.format("朝向已更改为:%s%n, 当前位置:【%d,%d】",
        		 currentDirection, row+1, column+1));
         repaint();
         break;
     case 5:  //向前移动
         if (moveRight)
             {
             currentDirection="东";
             if (penLocation)
                 for (int j=column;j<column+pace;j++)
                     positions[row][j]=1;
             column+=pace;
                          }
         else if(moveLeft)
        {currentDirection="西";
             if (penLocation)
                 for (int j=column;j>column-pace;j--)
                     positions[row][j]=1;
             column-=pace;
         }
         else if(moveDownwards)
         {currentDirection="南";
             if (penLocation)
              for (int i=row;i<row+pace;i++)	//已重写
                     positions[i][column]=1;
                 row+=pace;
                 }
         else if(moveUpwards)
        {currentDirection="北";
             if (penLocation)
                 for (int i=row;i>row-pace;i--)
                     positions[i][column]=1;
                 row-=pace;
         }
         drawingStatus.setText(String.format("朝向已更改为:%s%n, 当前位置:【%d,%d】",
        		 currentDirection, row+1, column+1));
         repaint();
         break;
     case 6://print turtle graphics,打印图形
    	 repaint();
         break;
     case 7://clear turtle graphics,擦除当前图形
         for (int i=0;i<20;i++)	//重置数组
             for(int j=0;j<20;j++)
                 positions[i][j]=0;
         turtleBehaviour(6);  //绘制空白画板
         row = column = 0; //重置画笔位置为画板左上角
         moveRight = true; //重置移动方向
         currentDirection="东";
         penLocation = false;
         drawingStatus.setText(String.format("图形已擦除。当前位置:【%d,%d】,当前朝向:%s" ,
        		 row+1, column+1, currentDirection));
         break;
     case 9://terminate the program
    	 drawingStatus.setText(String.format("绘制完成!"));
    	 System.exit(0);
         break;
     
     }

        
     }
 
 public void drawHuang() {
	 //示例指令:可绘制出“黄”字(以下指令通过Excel中的模板辅助创建而成)
	 pace = 5;
	 turtleBehaviour(5);
	 turtleBehaviour(3);
	 pace = 2;
	 turtleBehaviour(5);
	 turtleBehaviour(2);
	 pace = 4;
	 turtleBehaviour(5);
	 turtleBehaviour(3);
	 turtleBehaviour(3);
	 pace = 3;
	 turtleBehaviour(5);
	 turtleBehaviour(4);
	 pace =2;
	 turtleBehaviour(5);
	 turtleBehaviour(3);
	 turtleBehaviour(3);
	 pace =11;
	 turtleBehaviour(5);
	 turtleBehaviour(3);
	 turtleBehaviour(3);
	 pace =3;
	 turtleBehaviour(5);
	 turtleBehaviour(3);
	 pace =1;
	 turtleBehaviour(5);
	 turtleBehaviour(3);
	 turtleBehaviour(3);
	 pace =4;
	 turtleBehaviour(5);
	 turtleBehaviour(3);
	 pace =8;
	 turtleBehaviour(5);
	 turtleBehaviour(3);
	 turtleBehaviour(3);
	 pace =11;
	 turtleBehaviour(5);
	 turtleBehaviour(3);
	 turtleBehaviour(3);
	 pace =6;
	 turtleBehaviour(5);
	 turtleBehaviour(4);
	 pace =6;
	 turtleBehaviour(5);
	 turtleBehaviour(3);
	 pace =4;
	 turtleBehaviour(5);
	 turtleBehaviour(3);
	 pace =4;
	 turtleBehaviour(5);
	 turtleBehaviour(3);
	 pace =8;
	 turtleBehaviour(5);
	 turtleBehaviour(3);
	 pace =4;
	 turtleBehaviour(5);
	 turtleBehaviour(3);
	 pace =4;
	 turtleBehaviour(5);
	 turtleBehaviour(3);
	 pace =3;
	 turtleBehaviour(5);
	 turtleBehaviour(3);
	 turtleBehaviour(3);
	 pace =1;
	 turtleBehaviour(5);
	 turtleBehaviour(3);
	 pace =3;
	 turtleBehaviour(5);
	 turtleBehaviour(3);
	 turtleBehaviour(3);
	 pace =8;
	 turtleBehaviour(5);
	 turtleBehaviour(1);	
	 turtleBehaviour(3);	
	 pace =4;	
	 turtleBehaviour(5);	
	 turtleBehaviour(3);	
	 pace =6;	
	 turtleBehaviour(5);	
	 turtleBehaviour(2);	
	 turtleBehaviour(1);	
	 pace =1;	
	 turtleBehaviour(5);	
	 turtleBehaviour(2);		
	 pace =1;	
	 turtleBehaviour(5);
	 turtleBehaviour(4);
	 turtleBehaviour(1);
	 pace =1;	
	 turtleBehaviour(5);
	 turtleBehaviour(2);
	 pace =1;	
	 turtleBehaviour(5);
	 turtleBehaviour(3);	//右转
	 turtleBehaviour(1);	//提笔
	 pace =1;				//走一步
	 turtleBehaviour(5);
	 turtleBehaviour(2);	//落笔
	 pace =1;				//走一步
	 turtleBehaviour(5);
	 turtleBehaviour(1);	//提笔
	 turtleBehaviour(4);	//左转
	 turtleBehaviour(1);	//提笔
	 pace =1;				//走一步
	 turtleBehaviour(5);
	 turtleBehaviour(2);	//落笔
	 pace =1;				//走一步
	 turtleBehaviour(5);
	 turtleBehaviour(1);	//提笔 (黄字缺一撇)
	 turtleBehaviour(4);	//左转
	 pace =10;				//走10步
	 turtleBehaviour(5);		
	 turtleBehaviour(4);	//左转
	 pace =1;				//走1步
	 turtleBehaviour(5);
	 turtleBehaviour(2);	//落笔
	 pace =1;				//走1步
	 turtleBehaviour(5);
	 turtleBehaviour(4);	//左转
	 turtleBehaviour(1);	//提笔
	 pace =1;				//走1步
	 turtleBehaviour(5);
	 turtleBehaviour(2);	//落笔
	 pace =1;				//走1步
	 turtleBehaviour(5);
	 turtleBehaviour(1);	//提笔
	 turtleBehaviour(3);	//右转
	 pace =1;				//走1步
	 turtleBehaviour(5);
	 turtleBehaviour(2);	//落笔
	 turtleBehaviour(3);	//右转
	 pace =1;				//走1步
	 turtleBehaviour(5);
	 turtleBehaviour(1);	//提笔
	 turtleBehaviour(4);	//左转
	 pace =1;				//走1步
	 turtleBehaviour(5);
	 turtleBehaviour(4);	//左转
	 pace =2;				//走1步
	 turtleBehaviour(5);
	 turtleBehaviour(2);	//落笔
	 pace =1;				//走1步
	 turtleBehaviour(5);
	 
	
}
 
 public void drawHong() {
	 //示例初始数组:可绘制出“鸿”字(以下指令通过Excel中的模板辅助创建而成)

		positions[0][0]=0;	positions[0][1]=0;	positions[0][2]=0;	positions[0][3]=0;	positions[0][4]=0;	positions[0][5]=0;	positions[0][6]=0;	positions[0][7]=0;	positions[0][8]=0;	positions[0][9]=0;	positions[0][10]=0;	positions[0][11]=0;	positions[0][12]=0;	positions[0][13]=0;	positions[0][14]=0;	positions[0][15]=0;	positions[0][16]=0;	positions[0][17]=0;	positions[0][18]=0;	positions[0][19]=0;
		positions[1][0]=0;	positions[1][1]=0;	positions[1][2]=0;	positions[1][3]=0;	positions[1][4]=0;	positions[1][5]=0;	positions[1][6]=0;	positions[1][7]=0;	positions[1][8]=0;	positions[1][9]=0;	positions[1][10]=0;	positions[1][11]=0;	positions[1][12]=0;	positions[1][13]=0;	positions[1][14]=0;	positions[1][15]=0;	positions[1][16]=0;	positions[1][17]=0;	positions[1][18]=0;	positions[1][19]=0;
		positions[2][0]=0;	positions[2][1]=0;	positions[2][2]=0;	positions[2][3]=0;	positions[2][4]=0;	positions[2][5]=0;	positions[2][6]=0;	positions[2][7]=0;	positions[2][8]=0;	positions[2][9]=0;	positions[2][10]=0;	positions[2][11]=0;	positions[2][12]=0;	positions[2][13]=0;	positions[2][14]=0;	positions[2][15]=0;	positions[2][16]=0;	positions[2][17]=0;	positions[2][18]=0;	positions[2][19]=0;
		positions[3][0]=0;	positions[3][1]=0;	positions[3][2]=0;	positions[3][3]=0;	positions[3][4]=0;	positions[3][5]=0;	positions[3][6]=0;	positions[3][7]=0;	positions[3][8]=0;	positions[3][9]=0;	positions[3][10]=0;	positions[3][11]=0;	positions[3][12]=0;	positions[3][13]=1;	positions[3][14]=1;	positions[3][15]=1;	positions[3][16]=0;	positions[3][17]=0;	positions[3][18]=0;	positions[3][19]=0;
		positions[4][0]=0;	positions[4][1]=0;	positions[4][2]=0;	positions[4][3]=0;	positions[4][4]=0;	positions[4][5]=0;	positions[4][6]=0;	positions[4][7]=0;	positions[4][8]=0;	positions[4][9]=0;	positions[4][10]=0;	positions[4][11]=0;	positions[4][12]=1;	positions[4][13]=0;	positions[4][14]=0;	positions[4][15]=0;	positions[4][16]=0;	positions[4][17]=0;	positions[4][18]=0;	positions[4][19]=0;
		positions[5][0]=0;	positions[5][1]=0;	positions[5][2]=1;	positions[5][3]=0;	positions[5][4]=0;	positions[5][5]=0;	positions[5][6]=0;	positions[5][7]=0;	positions[5][8]=0;	positions[5][9]=0;	positions[5][10]=0;	positions[5][11]=1;	positions[5][12]=0;	positions[5][13]=0;	positions[5][14]=0;	positions[5][15]=0;	positions[5][16]=0;	positions[5][17]=0;	positions[5][18]=0;	positions[5][19]=0;
		positions[6][0]=0;	positions[6][1]=0;	positions[6][2]=0;	positions[6][3]=1;	positions[6][4]=0;	positions[6][5]=0;	positions[6][6]=0;	positions[6][7]=0;	positions[6][8]=0;	positions[6][9]=0;	positions[6][10]=0;	positions[6][11]=1;	positions[6][12]=1;	positions[6][13]=1;	positions[6][14]=1;	positions[6][15]=1;	positions[6][16]=0;	positions[6][17]=0;	positions[6][18]=0;	positions[6][19]=0;
		positions[7][0]=0;	positions[7][1]=0;	positions[7][2]=0;	positions[7][3]=0;	positions[7][4]=1;	positions[7][5]=0;	positions[7][6]=1;	positions[7][7]=1;	positions[7][8]=1;	positions[7][9]=1;	positions[7][10]=0;	positions[7][11]=1;	positions[7][12]=0;	positions[7][13]=0;	positions[7][14]=0;	positions[7][15]=1;	positions[7][16]=0;	positions[7][17]=0;	positions[7][18]=0;	positions[7][19]=0;
		positions[8][0]=0;	positions[8][1]=0;	positions[8][2]=0;	positions[8][3]=0;	positions[8][4]=0;	positions[8][5]=0;	positions[8][6]=0;	positions[8][7]=0;	positions[8][8]=0;	positions[8][9]=0;	positions[8][10]=0;	positions[8][11]=1;	positions[8][12]=1;	positions[8][13]=1;	positions[8][14]=0;	positions[8][15]=1;	positions[8][16]=0;	positions[8][17]=0;	positions[8][18]=0;	positions[8][19]=0;
		positions[9][0]=0;	positions[9][1]=0;	positions[9][2]=1;	positions[9][3]=1;	positions[9][4]=1;	positions[9][5]=0;	positions[9][6]=0;	positions[9][7]=0;	positions[9][8]=0;	positions[9][9]=0;	positions[9][10]=0;	positions[9][11]=1;	positions[9][12]=0;	positions[9][13]=0;	positions[9][14]=0;	positions[9][15]=1;	positions[9][16]=0;	positions[9][17]=0;	positions[9][18]=0;	positions[9][19]=0;
		positions[10][0]=0;	positions[10][1]=0;	positions[10][2]=0;	positions[10][3]=0;	positions[10][4]=0;	positions[10][5]=0;	positions[10][6]=1;	positions[10][7]=1;	positions[10][8]=1;	positions[10][9]=1;	positions[10][10]=0;	positions[10][11]=1;	positions[10][12]=0;	positions[10][13]=0;	positions[10][14]=0;	positions[10][15]=1;	positions[10][16]=0;	positions[10][17]=0;	positions[10][18]=0;	positions[10][19]=0;
		positions[11][0]=0;	positions[11][1]=0;	positions[11][2]=0;	positions[11][3]=0;	positions[11][4]=1;	positions[11][5]=0;	positions[11][6]=0;	positions[11][7]=0;	positions[11][8]=0;	positions[11][9]=0;	positions[11][10]=0;	positions[11][11]=1;	positions[11][12]=1;	positions[11][13]=1;	positions[11][14]=1;	positions[11][15]=1;	positions[11][16]=0;	positions[11][17]=0;	positions[11][18]=0;	positions[11][19]=0;
		positions[12][0]=0;	positions[12][1]=0;	positions[12][2]=0;	positions[12][3]=1;	positions[12][4]=0;	positions[12][5]=0;	positions[12][6]=0;	positions[12][7]=0;	positions[12][8]=0;	positions[12][9]=0;	positions[12][10]=0;	positions[12][11]=1;	positions[12][12]=0;	positions[12][13]=0;	positions[12][14]=0;	positions[12][15]=0;	positions[12][16]=0;	positions[12][17]=0;	positions[12][18]=0;	positions[12][19]=0;
		positions[13][0]=0;	positions[13][1]=0;	positions[13][2]=1;	positions[13][3]=0;	positions[13][4]=0;	positions[13][5]=0;	positions[13][6]=0;	positions[13][7]=0;	positions[13][8]=0;	positions[13][9]=0;	positions[13][10]=0;	positions[13][11]=1;	positions[13][12]=1;	positions[13][13]=1;	positions[13][14]=1;	positions[13][15]=1;	positions[13][16]=1;	positions[13][17]=0;	positions[13][18]=0;	positions[13][19]=0;
		positions[14][0]=0;	positions[14][1]=0;	positions[14][2]=0;	positions[14][3]=0;	positions[14][4]=0;	positions[14][5]=0;	positions[14][6]=0;	positions[14][7]=0;	positions[14][8]=0;	positions[14][9]=0;	positions[14][10]=0;	positions[14][11]=0;	positions[14][12]=0;	positions[14][13]=0;	positions[14][14]=0;	positions[14][15]=0;	positions[14][16]=1;	positions[14][17]=0;	positions[14][18]=0;	positions[14][19]=0;
		positions[15][0]=0;	positions[15][1]=0;	positions[15][2]=0;	positions[15][3]=0;	positions[15][4]=0;	positions[15][5]=0;	positions[15][6]=0;	positions[15][7]=0;	positions[15][8]=0;	positions[15][9]=0;	positions[15][10]=0;	positions[15][11]=1;	positions[15][12]=1;	positions[15][13]=1;	positions[15][14]=1;	positions[15][15]=0;	positions[15][16]=1;	positions[15][17]=0;	positions[15][18]=0;	positions[15][19]=0;
		positions[16][0]=0;	positions[16][1]=0;	positions[16][2]=0;	positions[16][3]=0;	positions[16][4]=0;	positions[16][5]=0;	positions[16][6]=0;	positions[16][7]=0;	positions[16][8]=0;	positions[16][9]=0;	positions[16][10]=0;	positions[16][11]=0;	positions[16][12]=0;	positions[16][13]=0;	positions[16][14]=0;	positions[16][15]=0;	positions[16][16]=1;	positions[16][17]=0;	positions[16][18]=0;	positions[16][19]=0;
		positions[17][0]=0;	positions[17][1]=0;	positions[17][2]=0;	positions[17][3]=0;	positions[17][4]=0;	positions[17][5]=0;	positions[17][6]=0;	positions[17][7]=0;	positions[17][8]=0;	positions[17][9]=0;	positions[17][10]=0;	positions[17][11]=0;	positions[17][12]=0;	positions[17][13]=1;	positions[17][14]=0;	positions[17][15]=0;	positions[17][16]=1;	positions[17][17]=0;	positions[17][18]=0;	positions[17][19]=0;
		positions[18][0]=0;	positions[18][1]=0;	positions[18][2]=0;	positions[18][3]=0;	positions[18][4]=0;	positions[18][5]=0;	positions[18][6]=0;	positions[18][7]=0;	positions[18][8]=0;	positions[18][9]=0;	positions[18][10]=0;	positions[18][11]=0;	positions[18][12]=0;	positions[18][13]=1;	positions[18][14]=1;	positions[18][15]=1;	positions[18][16]=1;	positions[18][17]=0;	positions[18][18]=0;	positions[18][19]=0;
		positions[19][0]=0;	positions[19][1]=0;	positions[19][2]=0;	positions[19][3]=0;	positions[19][4]=0;	positions[19][5]=0;	positions[19][6]=0;	positions[19][7]=0;	positions[19][8]=0;	positions[19][9]=0;	positions[19][10]=0;	positions[19][11]=0;	positions[19][12]=0;	positions[19][13]=0;	positions[19][14]=0;	positions[19][15]=0;	positions[19][16]=0;	positions[19][17]=0;	positions[19][18]=0;	positions[19][19]=0;
 }

public JTextField getInstructionJTextField() {
	return instructionJTextField;
}

public void setInstructionJTextField(JTextField instructionJTextField) {
	this.instructionJTextField = instructionJTextField;
}

public JTextField getPaceJTextField() {
	return paceJTextField;
}

public void setPaceJTextField(JTextField paceJTextField) {
	this.paceJTextField = paceJTextField;
}

 }

 2. 测试类

import java.awt.BorderLayout;
import javax.swing.JFrame;




public class TurtleGraphicsTest {

	 // create a new frame to hold the panel
	private static JFrame application = new JFrame();
	
	
	public static void main(String[] args)
	{
	 // create a panel that contains our drawing
	 TurtleGraphicsJPanel panel = new TurtleGraphicsJPanel();

	 application.setTitle("海龟绘图语言");
	 
	 // set the frame to exit when it is closed
	 application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	 application.add(panel,BorderLayout.CENTER); // add the panel to the frame
	 application.setSize(1000, 626); // set the size of the frame
	 application.setVisible(true); // make the frame visible    
	 
	 
	} 
	
	}
	

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值