| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 656 人关注过本帖
标题:一个有错误的程序
只看楼主 加入收藏
lyccs999
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-4-23
收藏
 问题点数:0 回复次数:6 
一个有错误的程序

我编译了有两处错误 但是我不知道怎么改哦~这个程序是实现用键盘的上下左右控制button的移动
import java.awt.event.*;import java.applet.*;
import java.awt.*;
public class 1
{ button b_go=new button("go"),
int b_x=0,b_y=0;
public void init()
{ b_go.addkeylistener(this);
}
public void keypressed(keyevent e)
{ if(e.getkeycode()==leyevent.VK_UP)
{ rectangle rect=new rectangle(b_x,b_y,20,20);
b_y=b_y-2;b_go.setlocation(b_x,b_y);
}
if(e.getkeycode()==leyevent.VK_DOWN)
{ rectangle rect=new rectangle(b_x,b_y,20,20);
b_y=b_y+2;b_go.setlocation(b_x,b_y);
}
if(e.getkeycode()==leyevent.VK_RIGHT)
{ rectangle rect=new rectangle(b_x,b_y,20,20);
b_x=b_x+2;b_go.setlocation(b_x,b_y);
}
if(e.getkeycode()==leyevent.VK_LETT)
{ rectangle rect=new rectangle(b_x,b_y,20,20);
b_x=b_x-2;b_go.setlocation(b_x,b_y);
}
}
public void keyreleased(keyevent e){}
public vold keytyped(keyevent e){}
public voide actionperformed(actionevent e)
{ b_go.setbounds(22,45,20,20);
b_x=b_go.getbounds().x;b_y=b_go.getbounds().y;
b_go.requestfocus() ;
}
}

搜索更多相关主题的帖子: void 键盘 public button import 
2006-04-26 16:17
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
你这个程序何止两个错误
import java.awt.event.*;import java.applet.*;
import java.awt.*;
public class 1
{ button b_go=new button("go"),
int b_x=0,b_y=0;
public void init()
{ b_go.addkeylistener(this);
}
public void keypressed(keyevent e)
{ if(e.getkeycode()==leyevent.VK_UP)//怎么又变成了leyevent,错得太离谱了,keyevent还说得过去,也是错的,应该是大写的KeyEvent
{ rectangle rect=new rectangle(b_x,b_y,20,20);
b_y=b_y-2;b_go.setlocation(b_x,b_y);
}
if(e.getkeycode()==leyevent.VK_DOWN)
{ rectangle rect=new rectangle(b_x,b_y,20,20);
b_y=b_y+2;b_go.setlocation(b_x,b_y);
}
if(e.getkeycode()==leyevent.VK_RIGHT)
{ rectangle rect=new rectangle(b_x,b_y,20,20);
b_x=b_x+2;b_go.setlocation(b_x,b_y);
}
if(e.getkeycode()==leyevent.VK_LETT)
{ rectangle rect=new rectangle(b_x,b_y,20,20);
b_x=b_x-2;b_go.setlocation(b_x,b_y);
}
}
public void keyreleased(keyevent e){}
public vold keytyped(keyevent e){}
public voide actionperformed(actionevent e)
{ b_go.setbounds(22,45,20,20);
b_x=b_go.getbounds().x;b_y=b_go.getbounds().y;
b_go.requestfocus() ;
}
}
你把所有的东西都小写了,要记住在JAVA中,对大小写是很敏感的,很多方法中字母都在大写的
你还是把JAVA基本的东西学一下吧,这些事件处理的,以后可以慢慢学。不急的

可惜不是你,陪我到最后
2006-04-26 16:30
lyccs999
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-4-23
收藏
得分:0 
import java.awt.event.*;import java.applet.*;
import java.awt.*;
public class 1
{ Button b_go=new Button("go"),
int b_x=0,b_y=0;
public void init()
{ b_go.addkeylistener(this);
}
public void keyPressed(KeyEvent e)
{ if(e.getKeycode()==KeyEvent.VK_UP)
{ Rectangle rect=new Rectangle(b_x,b_y,20,20);
b_y=b_y-2;b_go.setLocation(b_x,b_y);
}
if(e.getKeycode()==KeyEvent.VK_DOWN)
{ Rectangle rect=new Rectangle(b_x,b_y,20,20);
b_y=b_y+2;b_go.setLocation(b_x,b_y);
}
if(e.getKeycode()==KeyEvent.VK_RIGHT)
{ Rectangle rect=new Rectangle(b_x,b_y,20,20);
b_x=b_x+2;b_go.setLocation(b_x,b_y);
}
if(e.getKeycode()==KeyEvent.VK_LETT)
{ Rectangle rect=new Rectangle(b_x,b_y,20,20);
b_x=b_x-2;b_go.setLocation(b_x,b_y);
}
}
public void keyReleased(KeyEvent e){}
public vold keyTyped(KeyEvent e){}
public voide actionPerFormed(ActionEvent e)
{ b_go.setBounds(22,45,20,20);
b_x=b_go.getBounds().x;b_y=b_go.getBounds().y;
b_go.requestFocus() ;
}
}
改过来了哦~还有什么地方哦?
2006-04-26 16:50
wtyl0088
Rank: 1
等 级:新手上路
帖 子:109
专家分:0
注 册:2006-3-24
收藏
得分:0 

/*<applet code="l.class" width=200 height=200>
</applet>*/
import java.awt.event.*;
import java.applet.*;
import java.awt.*;
import javax.swing.*;

public class l extends JApplet implements KeyListener,ActionListener
{
Container cp;
Button b_go=new Button("go");
int b_x=0,b_y=0;

public void init()
{
cp=getContentPane();
cp.add(b_go);
b_go.addKeyListener(this);
b_go.addActionListener(this);
}

public void keyPressed(KeyEvent e)
{
if(e.getKeyCode()==KeyEvent.VK_UP)
{
Rectangle rect=new Rectangle(b_x,b_y,20,20);
//g.drawRect(b_x,b_y,20,20);
b_y=b_y-2;
b_go.setLocation(b_x,b_y);
//g.drawRect(rect);
}

if(e.getKeyCode()==KeyEvent.VK_DOWN)
{
Rectangle rect=new Rectangle(b_x,b_y,20,20);
b_y=b_y+2;b_go.setLocation(b_x,b_y);
}
if(e.getKeyCode()==KeyEvent.VK_RIGHT)

{
Rectangle rect=new Rectangle(b_x,b_y,20,20);
b_x=b_x+2;b_go.setLocation(b_x,b_y);

}
if(e.getKeyCode()==KeyEvent.VK_LEFT)
{
Rectangle rect=new Rectangle(b_x,b_y,20,20);
b_x=b_x-2;b_go.setLocation(b_x,b_y);
}
}
public void keyReleased(KeyEvent e){}
public void keyTyped(KeyEvent e){}
public void actionPerformed(ActionEvent e)
{ b_go.setBounds(22,45,20,20);
b_x=b_go.getBounds().x;b_y=b_go.getBounds().y;
b_go.requestFocus() ;
}

}

[此贴子已经被作者于2006-4-27 18:34:31编辑过]


2006-04-27 18:15
wtyl0088
Rank: 1
等 级:新手上路
帖 子:109
专家分:0
注 册:2006-3-24
收藏
得分:0 
已经可以了 你程序错误太多了 真是受不了

[此贴子已经被作者于2006-4-27 18:35:40编辑过]


2006-04-27 18:22
zhouxin
Rank: 2
等 级:新手上路
威 望:4
帖 子:76
专家分:0
注 册:2006-4-28
收藏
得分:0 
这会儿忙!
等我看了再说!

好好编程好好学习
2006-04-28 23:46
ud3776034
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-4-29
收藏
得分:0 
是很难啊
2006-04-29 16:57
快速回复:一个有错误的程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017792 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved