请最大化后看,有一行缩上去了,hehe

解决方案 »

  1.   

    import java.awt.*;
    import java.util.*;
    import java.awt.event.*;
    import javax.swing.*;public class Maze extends JFrame
    {
      GameMap gameMap=new GameMap();  public Maze()
      {
         super("My First Game");
         setBounds(300,200,470,470);
         setResizable(false);
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
         JPanel pane=new JPanel();
         pane.add(gameMap);
         setContentPane(pane);
         show();
      }  public static void main(String[] args)
      {
         Maze maze=new Maze();
      }
    }class GameMap extends JPanel implements KeyListener
    {
       Numen numen=new Numen();   public GameMap()
      {
         this.add(numen);
         addKeyListener(this);
       }
       
      public void keyTyped(KeyEvent e) 
      {
      
      }
      
      public void keyPressed(KeyEvent evt)
      {
         int keyCode=evt.getKeyCode();
         switch (keyCode)
        {
           case KeyEvent.VK_UP:
                  numen.playMove(1);
           case KeyEvent.VK_DOWN:
                  numen.playMove(2);
           case KeyEvent.VK_LEFT:
                  numen.playMove(3);
           case KeyEvent.VK_RIGHT:
                 numen.playMove(4); 
         } 
       }   public void keyReleased(KeyEvent evt)
       {
            numen.stopMove();
        }//public static void main(String[] args)
    //{
    // Maze maze=new Maze();
    //}
    }class Numen extends JPanel implements Runnable
    {
       private Thread runner;
       Image numenPic;
       int xNow=0;
       int yNow=0;
       int wayCortrol=0;   Numen()
       {
          super();
          setBackground(Color.white);
          MediaTracker track=new MediaTracker(this);        
          Toolkit kit=Toolkit.getDefaultToolkit();
          numenPic=kit.getImage("test.gif");
          track.addImage(numenPic,0);
          try
           {
               track.waitForAll();
            }
           catch (InterruptedException e)
          {
            }
        }void playMove(int setCortrol)
    {
       wayCortrol=setCortrol;
       if (runner==null&&wayCortrol!=0)
       {
          runner=new Thread(this);
          runner.start();
        }
    }void stopMove()
    {
    if (runner!=null)
    {
    runner=null;
    }
    }public void paintComponent(Graphics comp)
    {
    Graphics2D comp2D=(Graphics2D)comp;
    comp2D.setColor(Color.white);
    comp2D.fillRect(0,0,470,470);
    if(numenPic!=null)
    comp2D.drawImage(numenPic,xNow,yNow,this); 
    }public void run()
    {
    while (true)
    {
    switch (wayCortrol)
    {
    case 1:
    numenUp();
    break;
    case 2:
    numenDown();
    break;
    case 3:
    numenLeft();
    break;
    case 4:
    numenRight();
    break; 
    }
    }
    }void numenUp()
    {
    if (yNow>=0)
    {
    yNow=yNow-10;
    repaint();
    }
    }void numenDown()
    {
    if (yNow<=410)
    {
    yNow=yNow+10;
    repaint();
    }
    }void numenLeft()
    {
    if (xNow>=0)
    {
    xNow=xNow-10;
    repaint();
    }
    }void numenRight()
    {
    if (xNow<=410)
    {
    xNow=xNow+10;
    repaint();
    }
    }
    }
      

  2.   

    hexiaofeng(java爱好者) 你没对我的程序做修改啊??
      

  3.   

    改了,你编译我的代码了么???????????????看这个新的import java.awt.*;
    import java.util.*;
    import java.awt.event.*;
    import javax.swing.*;public class Maze extends JFrame
    {
      GameMap gameMap=new GameMap();  public Maze()
      {
         super("My First Game");
         setBounds(300,200,470,470);
         setResizable(false);
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
         JPanel pane=new JPanel();
         pane.setLayout(new BorderLayout());
         pane.add(gameMap);
         setContentPane(pane);
         show();
      }  public static void main(String[] args)
      {
         Maze maze=new Maze();
      }
    }class GameMap extends JPanel implements KeyListener
    {
       Numen numen=new Numen();   public GameMap()
      {
         setLayout(new BorderLayout());
         this.add(numen);
         addKeyListener(this);
       }
       
      public void keyTyped(KeyEvent e) 
      {
      
      }
      
      public void keyPressed(KeyEvent evt)
      {
         int keyCode=evt.getKeyCode();
         switch (keyCode)
        {
           case KeyEvent.VK_UP:
                  numen.playMove(1);
           case KeyEvent.VK_DOWN:
                  numen.playMove(2);
           case KeyEvent.VK_LEFT:
                  numen.playMove(3);
           case KeyEvent.VK_RIGHT:
                 numen.playMove(4); 
         } 
       }   public void keyReleased(KeyEvent evt)
       {
            numen.stopMove();
        }//public static void main(String[] args)
    //{
    // Maze maze=new Maze();
    //}
    }class Numen extends JPanel implements Runnable
    {
       private Thread runner;
       Image numenPic;
       int xNow=0;
       int yNow=0;
       int wayCortrol=0;   Numen()
       {
          super();
          setBackground(Color.white);
          MediaTracker track=new MediaTracker(this);        
          Toolkit kit=Toolkit.getDefaultToolkit();
          numenPic=kit.getImage("test.gif");
          track.addImage(numenPic,100);
          try
           {
               track.waitForAll();
            }
           catch (InterruptedException e)
          {
            }
        }void playMove(int setCortrol)
    {
       wayCortrol=setCortrol;
       if (runner==null&&wayCortrol!=0)
       {
          runner=new Thread(this);
          runner.start();
        }
    }   void stopMove()
       {
          if (runner!=null)
          {
             runner=null;
           }
       }public void paintComponent(Graphics comp)
    {
       Graphics2D comp2D=(Graphics2D)comp;
       comp2D.setColor(Color.white);
       comp2D.fillRect(0,0,470,470);
       if(numenPic!=null)
         comp2D.drawImage(numenPic,xNow,yNow,this); 
    }public void run()
    {
       while (true)
       {
          switch (wayCortrol)
         {
            case 1:
                numenUp();
                break;
            case 2:
                numenDown();
                break;
            case 3:
                numenLeft();
                break;
            case 4:
                numenRight();
                break; 
          }
       }
    }void numenUp()
    {
       if (yNow>=0)
       {
          yNow=yNow-10;
          repaint();
        }
    }void numenDown()
    {
    if (yNow<=410)
    {
    yNow=yNow+10;
    repaint();
    }
    }void numenLeft()
    {
    if (xNow>=0)
    {
    xNow=xNow-10;
    repaint();
    }
    }void numenRight()
    {
    if (xNow<=410)
    {
    xNow=xNow+10;
    repaint();
    }
    }
    }
      

  4.   

    Maze.java:30: GameMap should be declared abstract; it does not define keyTyped(j
    ava.awt.event.KeyEvent) in GameMap
    class GameMap extends JPanel implements KeyListener
    ^
    GameMap加
    public void keyTyped(KeyEvent e) 
      {
      
      }
    Maze.java:92: cannot resolve symbol
    symbol  : method addImage  (java.awt.Image)
    location: class java.awt.MediaTracker
                    track.addImage(numenPic);
                   ~~~~~~~~~~少一个参数 

     track.addImage(numenPic,1);
                     
                        ^
    2 errors