首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

怎的在Eclipse中输入↑↓→←求大神详细解释

2012-09-10 
怎样在Eclipse中输入↑↓→←求大神详细解释我是想在控制台中输入上下左右键,但是这里是移动位置!!! 求大神[解

怎样在Eclipse中输入↑↓→←求大神详细解释
我是想在控制台中输入上下左右键,但是这里是移动位置!!! 求大神

[解决办法]
没遇到过。。。
[解决办法]
不知道你是不是要的这样的效果:
请输入一个上:↑
上:↑
请输入一个下:↓
下:↓
请输入一个左:←
左:←
请输入一个右:→
右:→

代码如下:
Scanner sc = new Scanner(System.in);
System.out.print("请输入一个上:");
String up = sc.nextLine();
System.out.println("上:"+up);
 
System.out.print("请输入一个下:");
String down = sc.nextLine();
System.out.println("下:"+down);
 
System.out.print("请输入一个左:");
String left = sc.nextLine();
System.out.println("左:"+left);
 
System.out.print("请输入一个右:");
String right = sc.nextLine();
System.out.println("右:"+right);
[解决办法]
控制台中做不到
[解决办法]

Java code
public class OtherTest extends JFrame {    private static final long serialVersionUID = 1L;    public static void main(String[] args) {        MyPanel mp = new MyPanel();        OtherTest ot = new OtherTest();        ot.add(mp);        ot.addKeyListener(mp);         ot.setSize(400, 300);        ot.setTitle("Moving XO");        ot.setLocationRelativeTo(null);        ot.setVisible(true);    }}class MyPanel extends JPanel implements KeyListener {    private static final long serialVersionUID = 1L;    int x = 10;    int y = 10;    public void paint(Graphics g) {        super.paint(g);        g.fillOval(x, y, 10, 10);    }    public void keyPressed(KeyEvent e) {        if (e.getKeyCode() == KeyEvent.VK_DOWN) {            y++;        } else if (e.getKeyCode() == KeyEvent.VK_UP) {            y--;        } else if (e.getKeyCode() == KeyEvent.VK_LEFT) {            x--;        } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {            x++;        }        this.repaint();    }    public void keyTyped(KeyEvent e) {        // TODO Auto-generated method stub            }    public void keyReleased(KeyEvent e) {        // TODO Auto-generated method stub            }    } 

热点排行