1.构造方法中的isfull[]应该不用重新定义
boolean isfull[]={true,true,true,false,false,false,true,true,true};
改为:
isfull = {true,true,true,false,false,false,true,true,true};2.e.getSource() == b1不是标准的方法
e.getSource()返回的是Object,b1也是Object,用==只能判断它们是否指向内存中的同一对象。不可否认,由于java对于对象分配内存空间的方法是先查找内存中是否有相同的对象,如有就指向它,会使==有时和equals()方法等效。但对于每个类的对象,java都提供了equals()方法,在判断值是否相等时,应该使用equals()方法。

解决方案 »

  1.   

    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class den extends JFrame  {
    int i,j;
    JButton b1;
    boolean isfull[],path[][];
    public static void main(String args[]){
    den myden=new den();
    myden.setSize(200,200);
    myden.getContentPane().invalidate();
    myden.getContentPane().validate();
    myden.getContentPane().repaint();
    myden.setVisible(true);
    }
    den(){
    super("dentance test");
    i=0;
    j=8;
    boolean isfull2[]={true,true,true,false,false,false,true,true,true};
    isfull= new boolean[isfull2.length];
    for(int i=0;i<isfull.length;i++)
    isfull[i]=isfull2[i];
    b1=new JButton("dentance");
    path=new boolean[9][9];
    getContentPane().add(b1);
    listen listen1=new listen();
    b1.addActionListener(listen1);
    this.getContentPane().setLayout(new FlowLayout());
    this.getContentPane().add(b1);
    }
    class listen implements ActionListener{
      public void actionPerformed(ActionEvent e){
    if (e.getSource()==b1){
    for(int i=0;i<9;i++){
      for(int j=0;j<9;j++){
    boolean isfulled=isfull[j];
    if(((Math.abs(i-j)==1&&i!=2&&i!=5)||Math.abs(i-j)==3||(Math.abs(i-j)==4&&(i==0||i==4||i==8))||(Math.abs(i-j)==2&&(i==2||i==4||i==6)))&&isfulled==false)
    path[i][j]=true;
    else path[i][j]=false;
      }
            }
    if(path[0][3]==true)
    b1.setText(convert(i,j));
    }
     }
        }
    public String convert(int i,int j){
    int s=0;
    i=add(s,j);
    j=add(i,j);
    return "win";
    }
    public int add(int i,int j){
    return i+j;
    }

    }
      

  2.   

    thanks ,all kindhearts!but can Masterz tell me why do you do that change?i'm a java beginner,have much to know,thanks .
                                                            dentance
      

  3.   

    问:为什么要做如下修改:
    1,用for来为isfull赋值;
    2,myden.getContentPane().invalidate();
    myden.getContentPane().validate();
    myden.getContentPane().repaint();
    3,为什么要用this指针?
    深盼回答为谢;
      

  4.   

    1,isfull = {...}这种形式只能在数组初始化时进行,如果一个数组在定义时没有初始化,那么就需要在使用前赋值了.当然可以把一个数组赋值给另一个数组,这样做就使两个数组指向同一区域(即是引用同一数组),更好的方法当然是将其new一个数组,对其进行一个的赋值啊.可看下一个例子可知:
    //: Arrays.java
    // Arrays of primitives.public class Arrays {
      public static void main(String[] args) {
        boolean[] a1 = { true, false, true, true, false };
        boolean[] a2;
        a2 = a1;
    System.out.println(a2.length);
        for(int i = 0; i < a2.length; i++)
          prt("a2[" + i + "] = " + a2[i]);
    a2[0] = false;
        for(int i = 0; i < a1.length; i++)
          prt("a1[" + i + "] = " + a1[i]);
    boolean[] a3 = {false,false,false,true,true};
    boolean[] a4 = new boolean[a2.length];
    for (int i = 0;i < a3.length ;i++)
    {
    a4[i] = a3[i];
    }
    a4[3] = false;
    for(int i =0;i < a3.length;i++)
    prt("a3[" + i + "] = " + a3[i]);
      }
      static void prt(String s) {
        System.out.println(s);
      }
    } ///:~
    至于this指针表示当前实例的方法调用,在这儿我认为好像不是必要吧.