欢迎来到天天文库
浏览记录
ID:30933309
大小:72.00 KB
页数:3页
时间:2019-01-04
《键盘控制光标移动》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、packagevisitsysteminformation;importjava.awt.AWTException;importjava.awt.Color;importjava•awtawt.Robot;importjava.awt.eventJFrame;importjavax.swing2、Utilities;publicclassKeyBoardControlCursorMove{/***@paramargs*/publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubDemoWindow3dw=newDemoWindow3("键盘控制光标移动”);dw.setBounds(dw.getToolkit()停朽"住nSize()・width/3,dw・getToolkit()•getScreenSize().height/3,dw>getToolkit()>getScre3、enSize().width/3,dw・getToolkit()•getScreenSize().height/3);dw.setDefaultCloseOperation(3Frame.EXIT_ON_CLOSE);dw.setVisible(true);classDemoWindow3extendsDFrame{DrawPaneldp=newDrawPanel();publicDemoWindow3(Stringtitie){super(title);add(dp);}}classDrawPanelextends3PanelimplementsKeyL4、istener{Pointpoint=null;publicDrawPanel(){setBackground(Color//设置可以获取焦点,否则无法响应键盘操作this.setFocusable(true);this.addKeyListener(this);}publicvoidpaintComponent(Graphicsg){super.paintComporient(g);try{Robotrobot=newRobot();if(point==null){point=newPoint(this.getWidth()/2,this・getHeig5、ht()/2);//将窗体坐标转换为屏幕坐标Swinglltilities・convertPointToScreen(point,this);}//移动光标robot•mouseMove((int)point•getX(),(int)point•getY());}catch(AWTExceptione){//TODOAuto-generatedcatchblocke6、ssed(KeyEvente){//TODOAuto-generatedmethodstubswitch(e>getKeyCode()){caseKeyEventpoint•setLocation(point•getX(),break;caseKeyEvent.VK_DOIaIN:point•setLocation(point•getX()^break;caseKeyEvent.VK_LEFT:point•setLocation(point•getX()break;caseKeyEvent.VK_RIGHT:point•setLocation(point•7、getX()break;}repaint();}point.getY()-3);point.getY()+3);3,point.getY());3,point.getYO);publicvoidkeyReleased(KeyEvente){//TODOAuto-generatedmethodstub
2、Utilities;publicclassKeyBoardControlCursorMove{/***@paramargs*/publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubDemoWindow3dw=newDemoWindow3("键盘控制光标移动”);dw.setBounds(dw.getToolkit()停朽"住nSize()・width/3,dw・getToolkit()•getScreenSize().height/3,dw>getToolkit()>getScre
3、enSize().width/3,dw・getToolkit()•getScreenSize().height/3);dw.setDefaultCloseOperation(3Frame.EXIT_ON_CLOSE);dw.setVisible(true);classDemoWindow3extendsDFrame{DrawPaneldp=newDrawPanel();publicDemoWindow3(Stringtitie){super(title);add(dp);}}classDrawPanelextends3PanelimplementsKeyL
4、istener{Pointpoint=null;publicDrawPanel(){setBackground(Color//设置可以获取焦点,否则无法响应键盘操作this.setFocusable(true);this.addKeyListener(this);}publicvoidpaintComponent(Graphicsg){super.paintComporient(g);try{Robotrobot=newRobot();if(point==null){point=newPoint(this.getWidth()/2,this・getHeig
5、ht()/2);//将窗体坐标转换为屏幕坐标Swinglltilities・convertPointToScreen(point,this);}//移动光标robot•mouseMove((int)point•getX(),(int)point•getY());}catch(AWTExceptione){//TODOAuto-generatedcatchblocke6、ssed(KeyEvente){//TODOAuto-generatedmethodstubswitch(e>getKeyCode()){caseKeyEventpoint•setLocation(point•getX(),break;caseKeyEvent.VK_DOIaIN:point•setLocation(point•getX()^break;caseKeyEvent.VK_LEFT:point•setLocation(point•getX()break;caseKeyEvent.VK_RIGHT:point•setLocation(point•7、getX()break;}repaint();}point.getY()-3);point.getY()+3);3,point.getY());3,point.getYO);publicvoidkeyReleased(KeyEvente){//TODOAuto-generatedmethodstub
6、ssed(KeyEvente){//TODOAuto-generatedmethodstubswitch(e>getKeyCode()){caseKeyEventpoint•setLocation(point•getX(),break;caseKeyEvent.VK_DOIaIN:point•setLocation(point•getX()^break;caseKeyEvent.VK_LEFT:point•setLocation(point•getX()break;caseKeyEvent.VK_RIGHT:point•setLocation(point•
7、getX()break;}repaint();}point.getY()-3);point.getY()+3);3,point.getY());3,point.getYO);publicvoidkeyReleased(KeyEvente){//TODOAuto-generatedmethodstub
此文档下载收益归作者所有