//练习页面设计 
class MyPanel1 extends JPanel implements KeyListener
{ JButton button1,button2;
ImageIcon icon;
JLabel labelCat;
File f;
AudioClip clip;
int x,y;//获取当前标签的坐标位置;
Cursor c,c1;
MyPanel1()
{ button1=new JButton("回主页",new ImageIcon("背景2.jpg"));
button2=new JButton("游戏模式",new ImageIcon("背景2.jpg"));
icon=new ImageIcon("背景7.jpg");
labelCat=new JLabel(new ImageIcon("catUp.jpg"));
setLayout(null);
add(button2);
add(button1);
add(labelCat);labelCat.setBounds(390,650,120,60);
labelCat.addKeyListener(this);
c=new Cursor(Cursor.HAND_CURSOR);
c1=new Cursor(Cursor.MOVE_CURSOR);
//labelCat.requestFocusInWindow();
button1.setBounds(620,650,140,38);
button2.setBounds(620,700,140,38);
button2.setCursor(c);
button1.setCursor(c);
labelCat.setCursor(c1);
}
public void keyPressed(KeyEvent e){ JLabel label=(JLabel)e.getSource();
x=label.getBounds().x;
y=label.getBounds().y;
if(e.getKeyCode()==KeyEvent.VK_RIGHT)
{ x=x+5;
if(x>=620) x=600;
labelCat.setLocation(x,y);
}
else if(e.getKeyCode()==KeyEvent.VK_LEFT)
{ x=x-5;
if(x<=0) x=2;
labelCat.setLocation(x,y);
}
else if(e.getKeyCode()==KeyEvent.VK_UP)
{ y=y-5;
if(y<=300) y=290;
labelCat.setLocation(x,y);
}
else if(e.getKeyCode()==KeyEvent.VK_DOWN)
{ y=y+5;
if(y>=800) y=790;
labelCat.setLocation(x,y);
}  
else if(e.getKeyCode()==KeyEvent.VK_SPACE)
{  try{
f=new File("子弹的声音.wav");
URL url=f.toURL();
clip=Applet.newAudioClip(url);
clip.play();}
catch(Exception ert){}
}
}
public void keyTyped(KeyEvent e)
{ }
public void keyReleased(KeyEvent e)
{ }
public void paintComponent(Graphics g)

g.drawImage(icon.getImage(),0,0,780,800,this);
}