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";
}
}
}
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";
}
}
}
解决方案 »
- 用方法给成员变量赋值的问题,不懂
- 关于java中访问权限的一个疑惑
- struts问题 <html:hidden property="worklistStr" value="<bean:write name='worklistId'/>" />问题:谢谢...
- 一个奇怪的问题啊!!想获得自己web应用所在服务器的外网ip~~查看了很多~下面的方法都不行
- 问个socket的初学问题
- 依赖于抽象不对了?
- 判断a是不是B的实例??
- 请达人指教: Java与C++在对象数组初始化上的区别
- 安装了java2 sdk后,运行applet程序总是有问题
- 谁有api文档提供下载,别告诉去sun
- 关于jdk源码分析
- java的异常处理
for(int j=0;j<10;j++)
{
map1[i][j]= new Cell();
map1[i][j].value = map[i][j];
}
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},
};
这个不报错?神奇