想实现点开始,方块自动下落。不知道为什么,点了开始就不动了,按钮也不弹不上来。
谁解释下。import java.awt.*;
import javax.swing.*;
import java.awt.event.*;class huabu extends Canvas
{
int i=30,j=50;
huabu()
{
getSize();
}
public void paint(Graphics g)
{
setBackground(Color.red);
//g.drawString("hello",20,30);
g.setColor(Color.yellow);
g.fillRect(100,i,20,20);
g.fillRect(100,j,20,20);
g.fillRect(120,j,20,20);
g.fillRect(140,j,20,20);
i=i+10;
j=j+10;

}

public Dimension getPreferredSize()
{return new Dimension(300,400);}
}

class mianban extends JPanel implements ActionListener
{
JButton b1;
JButton b2;
huabu cav;
mianban()
{
setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
b1=new JButton("开始");
b2=new JButton("重置");
cav=new huabu();
add(cav);
add(b1);
add(b2);
b1.addActionListener(this);
b2.addActionListener(this);

}


public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
thread1 th=new thread1();
th.start(); /* for(int j=1;j<20;j++)
{
// cav.repaint();
try{Thread.sleep(500);}
catch(InterruptedException e1){}
cav.repaint();
}*/
}
if(e.getSource()==b2)
{cav.i=30;
cav.j=50;
cav.repaint();
}

}


class thread1 extends Thread
{
public void run()
{
for(int i=20;i>0;i--)
{
cav.repaint();
try{sleep(500);}
catch(InterruptedException e){}
}
}
}

}public class Fangkuai extends JFrame
{

mianban pane=new mianban();
Fangkuai()
{
super("方块程序");
getContentPane().add(pane);
setSize(400,600);
setVisible(true);

addWindowListener(new shut());

}
public static void main(String[] args)
{
Fangkuai fang=new Fangkuai();

}

}

class shut extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{System.exit(0);}
}