日期:2014-05-20 浏览次数:20927 次
import java.awt.*; import javax.swing.*; class Astar extends JPanel { int[][] map = { {1,1,0,0,0,0,0,0,0,0}, {1,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0}, {0,0,0,1,1,1,1,1,0,0}, {0,0,0,0,0,0,0,1,0,0}, {0,0,0,0,0,0,0,1,0,0}, {0,0,0,0,0,0,0,1,0,0}, {1,1,1,0,0,0,0,0,0,0}, {1,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,1,1,0,0}, }; Cell[][] map1; public Astar(){ map1 = new Cell[10][10]; for(int i=0;i<10;i++) for(int j=0;j<10;j++) map1[i][j].value = map[i][j]; JFrame f = new JFrame(); f.setBounds(100,100,600,500); f.add(this); f.setVisible(true); } public void paintComponent(Graphics g){ for(int i=0;i<10;i++){ for(int j=0;j<10;j++){ if(map[i][j]==0){ g.draw3DRect(40*j,40*i,40,40,true); g.drawString(map1[i][j].toString1(),40*j,40*i); } else if(map[i][j]==1) g.fill3DRect(40*j,40*i,40,40,true); } } } public static void main(String args[]){ new Astar(); } class Cell{ int value; boolean seen; boolean open; int direction; Cell(){ seen = true; open = true; } public String toString1(){ if(open) return "Open"; else return "Closed"; } } }