下面这段程序 程序已经编译成功  但运行出的效果中  似乎改变arrow方向的代码并没有执行喔
请问程序哪里出错了
//神枪手游戏
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
public class d2_01 extends JApplet implements ActionListener,
MouseListener,MouseMotionListener
{
  private Timer timer1,timer2,timer3;
  private ImgJPanel pan1;
  private Image image1;
  private JButton command;
  //命令按钮的图片文件名数组
  private String but_picname[]={"pic/start.jpg","pic/stop.jpg"};
  //成绩显示标签
  private JLabel score1= new JLabel("score : 0");
  //时间显示标签
  private JLabel time1=new JLabel("0");
  //显求发射器图案的标签
  private JLabel center1;
  //显示发射位置箭头的标签
  private JLabel weapon;
  //反馈信息标签
  private JLabel feedback = new JLabel("Successful!", JLabel.CENTER);
  //存放图库的数组
  private ImageIcon arrow[]=new ImageIcon[36];
  private ImageIcon body[]=new ImageIcon[2];
  private ImageIcon center_icon;
  private ImageIcon but_icon[]=new ImageIcon[2];
  private JLabel arrow_list[]=new JLabel[10];
  private JLabel body_list[]=new JLabel[10];
  //游戏状态变量
  private int game_status;
  private int p_score,p_time,px,py,pangle;
  private int center_x=256;
  private int center_y=308;
  private int flaglist[]=new int[10];
  private int counterlist[]=new int[10];
  private int pathno[]=new int[30];
  private int shiftlist[]=new int[30];
  private int offsetx[]=new int[10];
  private int offsety[]=new int[10];
  private int arrow_flag[]=new int[10];
  private int arrow_offsetx[]=new int[10];
  private int arrow_offsety[]=new int[10];
  private int arrow_shift[]=new int[10];
  private int arrow_rotation[]=new int[10];
  private int tpath[][]={
   {0,115,500,115},
   {500,85,0,85},
   {0,45,500,45},
   {500,145,0,145}
  }; 
  //初始化applet
  public void init()
    {
     //赋值变量c等于ContentPane
     Container c=getContentPane();
     c.setLayout(null);
     c.setSize(500,400);
     //加载背景图案
     try {image1 = getImage(new URL(getCodeBase(),
     "pic/background.jpg")); }
     catch(MalformedURLException e) {System.out.println(
     "下载图片文件发生错误 URL:"+e+"\n"); return; }
     //建立一个放置所有组件的panel
     pan1=new ImgJPanel(image1);
     pan1.setLayout(null);
     //设定pane1的尺寸
     pan1.setSize(500,400);
     pan1.addMouseListener(this);
     pan1.addMouseListener(this);
     try {
     //加载命令按钮的图案
     for(int i=0;i<2;i++){
      but_icon[i]=new ImageIcon(new URL(getCodeBase(),
      but_picname[i]));
     }
    }

解决方案 »

  1.   

    catch(MalformedURLException e) {System.out.println(
        "下载图片文件发生错误 URL:"+e+"\n"); return;}
        //在panel上建立一个command按钮
        command=new JButton(but_icon[0]);
        command.setSize(97,33);
        command.setLocation(285,362);
        command.addActionListener(this);
        pan1.add(command);
        //设定反馈信息标签的格式
        feedback.setBounds(40,80,420,60);
        feedback.setForeground(Color.yellow);
        feedback.setVisible(false);
        feedback.setFont(new Font("Arial",Font.PLAIN,36));
        //将反馈信息标签加入panel中
        pan1.add(feedback);
        loadpicture();
        weapon=new JLabel(arrow[0],JLabel.CENTER);
        weapon.setSize(41,41);
        weapon.setLocation(236,288);
        pan1.add(weapon);
        for(int i=0;i<10;i++){
         arrow_list[i]=new JLabel(arrow[0]);
         arrow_list[i].setSize(41,41);
         arrow_list[i].setVisible(false);
         pan1.add(arrow_list[i]);
            body_list[i]=new JLabel(body[0]);
            body_list[i].setSize(50,50);
         body_list[i].setVisible(false);
        pan1.add(body_list[i]);
         }
    center1=new JLabel(center_icon);
    center1.setSize(41,27);
    center1.setLocation(235,330);
    pan1.add(center1);
    //设定成绩显求标签的格式
    score1.setSize(140,24);
    score1.setForeground(Color.yellow);
    score1.setLocation(94,362);
    score1.setFont(new Font("Arial",Font.BOLD,16));
    //将成绩标签加入panel中
    pan1.add(score1);
    //设定时间显示标签的格式
      time1.setSize(80,24);
    time1.setForeground(Color.yellow);
    time1.setLocation(32,350);
    time1.setFont(new Font("Arial",Font.BOLD,16));
         //将成绩标签加入panel中
    pan1.add(time1);
    //将panel加入ContentPane中
      c.add(pan1);
    timer1=new Timer(1000,this);
    timer2=new Timer(100,this);
    timer3=new Timer(50,this);
          }
         //开始执行applet
         public void start()
          {
    game_status=0;
          }
         //加载图片
         public void loadpicture(){
           try {
         for(int i=0;i<36;i++){
          arrow[i]=new ImageIcon(new URL(getCodeBase(),"pic/a"+i+".gif"));
         }
          for(int i=0;i<2;i++){
           body[i]=new ImageIcon(new URL(getCodeBase(),"pic/s"+i+".gif"));
          }
          center_icon=new ImageIcon(new URL(getCodeBase(),
          "pic/center.gif"));
          }
          catch(MalformedURLException e) {System.out.println(
          "下载图片文件发生错误 URL:"+e+"\n"); return;}
         }
         //变更箭头对象的函数
         public void change_direction(int x,int y){
           if(game_status==1){
            double dx=x-center_x;
            double dy=center_y-y;
            double degree;
      

  2.   

    //计算箭头的角度
    if(dy==0){
        if(dx>0){
      degree=90;
    } else {
         degree=270;
        }
       }else {
     if(dy>0){
      degree=Math.atan(dx/dy)*180/Math.PI;
              } else {
       degree=Math.atan(dx/dy)*180/Math.PI+180;
            }
    }
           if(degree<0) degree=degree+360;
           //计算角度对应的图像对象编号
           int pno=(int)(degree/10)%36;
           pangle=pno;
           weapon.setIcon(arrow[pno]);
           px=x;
           py=y;
          }
        }
        //时间事件处理程序,每秒钟执行一次
        //显示新的body,显示时间
    public void t1(){
         int slot, i, pno;
          slot=-1;
          for(i=0;i<10;i++){
           //判断移动对象是否为隐藏状态
           if(flaglist[i]==0){
             slot=i;
     break;
    }
          }
           //判断是否找到隐藏状态的组件
           if(slot!=-1){
            //随机取得新的路径(共有4 个路径)
         pno=(int)(Math.random()*4);
         pathno[slot]=pno;
    //设定显示移动对象的开始位置
    body_list[slot].setLocation(tpath[pno][0],tpath[pno][1]);
    body_list[slot].setIcon(body[(int)(Math.random()*2)]);
    body_list[slot].setVisible(true);
    shiftlist[slot]=0;
    flaglist[slot]=1;
    //计算路径的间距
    offsetx[slot]=tpath[pno][2]-tpath[pno][0];
      offsety[slot]=0;
                  }
           p_time--;
           time1.setText(""+p_time);
           if(p_time==0){
      game_status=0;
      feedback.setText("Game Over!");
    timer1.stop();
    timer2.stop();
    timer3.stop();
    feedback.setVisible(true);
    command.setIcon(but_icon[0]);
    weapon.setIcon(arrow[0]);
                  }
          }
          //时间事件处理程序,每1/10秒钟执行一次
          //变换body的位置
    public void t2(){
      int i, pno, x, y;
      //调整移动对象位置的循环
      for(i=0;i<10;i++) {
      //判断移动是否为显示状态 
      if(flaglist[i]==1) {
        //判断是否为移动到目的地
        pno=pathno[i];
        shiftlist[i]=shiftlist[i]+1;
        if(shiftlist[i]<40) {
           //移动对象的坐标位置
           x=tpath[pno][0]+offsetx[i]*shiftlist[i]/40;
           y=tpath[pno][1];
           body_list[i].setLocation(x,y);
          } else {
            //将移动对象状态设定为0
            flaglist[i]=0;
            pathno[i]=-1;
            shiftlist[i]=0;
            //隐藏移动对象
            body_list[i].setVisible(false);
            }
          }
         }
    }
      

  3.   

    //时间事件处理程序,每1/20秒钟执行一次
    //变换arrow的位置
    public void t3(){
    int i, j, px, py, px2, py2, fg;
      for(i=0;i<10;i++) {
      //判断箭头对象是否已经发射出去
        if(arrow_flag[i]==1){
          fg=0;
          //判断箭头对象是否在发射进行中
          if(arrow_shift[i]<=4) {
            px= center_x+arrow_offsetx[i]*arrow_shift[i]/4;
            py= center_y+arrow_offsety[i]*arrow_shift[i]/4;
            arrow_list[i].setLocation(px,py);
            if(arrow_shift[i]==4) {
              //判断箭头是否射中气球
              for(j=0;j<10;j++) {
                 if(flaglist[j]==1) {
                   px=body_list[j].getLocation().x;
                   py=body_list[j].getLocation().y;
                   px2=arrow_list[i].getLocation().x+10;
                   py2=arrow_list[j].getLocation().y;
                   if(py2>py && py2<py+50 && px2>px && px2<px+50) {
                     //将移动对象状态设定为0
                       flaglist[j]=0;
                       pathno[j]=-1;
                       shiftlist[j]=0;
                       arrow_flag[i]=0;
                       arrow_list[i].setVisible(false);
                       body_list[j].setVisible(false);
                       fg=1;
                       //得分
                      p_score= p_score+10;
                      score1.setText("score:"+p_score);
                      break;
                    }
               }
           }
       }
    }else {
       //判断箭头对象是否为没有射中,若没射中就箭头向下掉落
         if(fg==0) {
         arrow_list[i].setIcon(arrow[18]);
         int x=arrow_list[i].getLocation().x;
         int y=arrow_list[i].getLocation().y;
         arrow_list[i].setLocation(x,y+15);
        }
     }
     arrow_shift[i]=arrow_shift[i]+1;
     if(arrow_shift[i]>=20) {
     //隐藏箭头对象
         arrow_list[i].setVisible(false);
         arrow_flag[i]=0;
        }
       }
     }
    }
    //发射新的箭头对象
    public void shoot() {
    int slot,i,pno;
    if(game_status==1) {
     slot=-1;
     //寻找空闲的箭头对象
      for(i=0;i<10;i++) {
       //判断箭头对象是否为隐藏状态  
       if(arrow_flag[i]==0) { 
        slot=i;
        break;
       }
     }
      //判断是否找到隐藏状态的箭头
      if(slot!=1) {
        //设定显示箭头的开始位置
          arrow_list[slot].setLocation(center_x,center_y);
          arrow_list[slot].setVisible(true);
          arrow_shift[slot]=0;
          arrow_flag[slot]=1;
          //计算路径的间距
          arrow_rotation[slot]=pangle;
          arrow_list[slot].setIcon(arrow[pangle]);
          arrow_offsetx[slot]=px-center_x;
          arrow_offsety[slot]=py-center_y;
          arrow_shift[slot]=0;
          }
        }
     }
      

  4.   

    还有最后一部分 大家请帮忙看看啊~~~~~~~~
    //按下命令钮时的事件处理程序
      public void actionPerformed(ActionEvent e) {
            int i;
            if(e.getSource()==command) {
              switch(game_status) {
               case 0://start  开始游戏
                 game_status=1;
                 for(i=0;i<10;i++) {
                   flaglist[i]=0;
                   body_list[i].setVisible(false);
                   arrow_flag[i]=0;
                   arrow_list[i].setVisible(false);
                  }
                 p_score=0;
                 p_time=60;
                 score1.setText("score:"+p_score);
                 time1.setText(""+p_time);
                 feedback.setVisible(false);
                 command.setIcon(but_icon[1]);
                 timer1.start();
                 timer2.start();
                 timer3.start();
                 break;
               case 1:   //stop  停止游戏
                 game_status=0;
                 feedback.setText("Stop!");
                 feedback.setVisible(true);
                 command.setIcon(but_icon[0]);
                 weapon.setIcon(arrow[0]);
                 timer1.stop();
                 timer2.stop();
                 timer3.stop();
                 break;
                }
               }
              if(game_status==1) {
               if(e.getSource() == timer1) t1();
               if(e.getSource() == timer2) t2();
               if(e.getSource() == timer3) t3();
              }
           }
             public void mousePressed(MouseEvent e) {}
             public void mouseReleased(MouseEvent e) {
             if(game_status==1) {
               shoot();
             }
            }
            public void mouseEntered(MouseEvent e) {}
            public void mouseExited(MouseEvent e) {}
            //按一下鼠标键的事件程序
            public void mouseClicked(MouseEvent e) {}
            //鼠标移动的事件处理程序
            public void mouseMoved(MouseEvent e) {
              int x,y;
              x=e.getX();
              y=e.getY();
              if(e.getSource() == pan1) {
               change_direction(x,y);
              }
            }
        //拖动鼠标的事件处理程序
        public void mouseDragged(MouseEvent e) {}
        //JPanel的扩展对象,用来放置背景图案
        class ImgJPanel extends JPanel
          {
            private Image image1;
            public ImgJPanel(Image image_a) {
                this.image1=image_a;
               }
            public void paintComponent (Graphics g)
              {
                g.drawImage(image1, 0, 0, this);
              }
           }
     }
      

  5.   

    JDK版本是?JVM运行时的版本是?
      

  6.   

    这个是从书上copy的,没有main,是一个appletion来的!
    因为刚刚入手,想调试一下看看效果,可与说明不同;
    所以也不知是代码原因还是其它……