当前位置: 代码迷 >> Java相关 >> [求助]有关打字游戏
  详细解决方案

[求助]有关打字游戏

热度:142   发布时间:2006-12-24 01:11:59.0
[求助]有关打字游戏

这是我增加了添加按纽,用来调速后的文件!
增加和改变的代码内容如下:
static int speed=1;

private void addButton(String label,ActionListener listener)
{
JButton button=new JButton(label);
button.addActionListener(listener);
md.add(button,BorderLayout.SOUTH);

}
ActionListener listener=new
ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String select=e.getActionCommand();
speed=Integer.parseInt(select);

}
};


public void run() //用线程循环更改Y值,并根据新的坐标在屏幕上重画pd[I];
{
while(true)
{fk();
panduan();
repaint();
try{
if(speed==1){myThread.sleep(50); }
if(speed==2){myThread.sleep(35); }
if(speed==3){myThread.sleep(20); }
}catch(Exception e) {}
}
}
还有不知道应该在哪个地方添加
addButton("1",listener);
addButton("2",listener);
addButton("3",listener);
好象错误的地方和要改进的地方很多,那位可以帮下!~
谢谢!~


[此贴子已经被作者于2006-12-24 1:13:31编辑过]

搜索更多相关的解决方案: 游戏  打字  

----------------解决方案--------------------------------------------------------
在主面板上加

还有我不知道myThread是哪个线程的引用

你最好还是用Thread.sleep来做好一些,因为sleep是静态方法

----------------解决方案--------------------------------------------------------
  相关解决方案