以下是我写的一个关于打地鼠的游戏程序,为什么运行起来有点问题,谁能帮我看一下啊
package com;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MousePlay implements ActionListener
{
private JFrame frame;
private Container contentPane;
private JButton btn[][]=new JButton[3][3];
private JLabel timeLbl,countLbl;
private Timer btnTimer,timer;
private JButton startBtn,exitBtn;
private int x,y;
public MousePlay()
{
frame=new JFrame("游戏");
frame.setBounds(200,200,500,500);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
contentPane=frame.getContentPane();
btnTimer=new Timer(500,this);
timer=new Timer(1000,this);
initGUI();
}
public void initGUI()
{
contentPane.setLayout(new BorderLayout());
timeLbl=new JLabel("0");
countLbl=new JLabel("0");
JPanel p1=new JPanel(new GridLayout(1,2));
p1.add(timeLbl);
p1.add(countLbl);
JPanel p2=new JPanel(new GridLayout(3,3));
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
btn[i][j]=new JButton(" ");
p2.add(btn[i][j]);
btn[i][j].setEnabled(false);
btn[i][j].addActionListener(this);
}
}
JPanel p3=new JPanel(new FlowLayout());
startBtn=new JButton("开始");
exitBtn=new JButton("退出");
p3.add(startBtn);
p3.add(exitBtn);
contentPane.add(p1,BorderLayout.NORTH);
contentPane.add(p2,BorderLayout.CENTER);
contentPane.add(p3,BorderLayout.SOUTH);
startBtn.addActionListener(this);
exitBtn.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==timer)
{
int v=timeLbl.getText().trim();
v--;
timeLbl.setText(v+"");
if(v==0)
{
timer.stop();
btnTimer.stop();
JOptionPane.showMessageDialog(null,new String("您的分数为"+countLbl.getText()),"恭喜!",JOptionPane.INFORMATION_MESSAGE,new ImageIcon("logo.gif"));
timeLbl.setText("0");
countLbl.setText("0");
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
{
btn[i][j].setEnabled(false);
btn[i][j].setText("");
}
startBtn.setEnabled(true);
}
}
if(e.getSource()==btnTimer)
{
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
btn[i][j].setText("");
x=(int)(Math.random()*3);
y=(int)(Math.random()*3);
btn[x][y].setText("Mouse!");
}
if(e.getSource()==startBtn)
{
timeLbl.setText(20+"");
timer.start();
btnTimer.start();
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
btn[i][j].setEnabled(true);
startBtn.setEnabled(false);
}
if(e.getSource()==exitBtn)
{
System.exit(0);
}
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if(e.getSource()==btn[i][j])
{
if(i==x&&j==y)
{
int cent=Integer.parseInt(countLbl.getText().trim());
cent++;
countLbl.setText(cent+"");
}
}
}
}
}
public void go()
{
frame.setVisible(true);
}
public static void main(String args[])
{
(new MousePlay()).go();
}
----------------解决方案--------------------------------------------------------