this code is working properly but the only one problem is that to move the cursor from top to bottom, i have to press down key so many times..... I need any dragging concept to move the cursor.... i mean once i keep pressed a key for some time, cursor moves continue. In the above program, to move cursor, one has to keep press and unpressed the key continue.
You can do it using - keyRepeated() and pointerPressed(int x,int y) is not needed for this.
OR
You can do this by starting a loop that keep's on repeating the Cursor movement i.e. (cursorY-- / cursorY++/cursorX++/cursorX--) & calling repaint() in in your keyPressed() method till keyRelease() is not called, by using a global boolean variable repeat.
try
Code:
// declare a call level boolean variable repeat at the start of your class
void keyPressed(int keyCode){
int key=keyCode;
repeat= true;
do while(repeat){
switch(key){
case -1: // to move up the cursor
cursorY--;
repaint();
break;
case -2: // to move down the cursor
cursorY++;
repaint();
break;
case -1: // to move left the cursor
cursorX--;
repaint();
break;
case -1: // to move right the cursor
cursorX++;
repaint();
break;
default:
repaint();
break;
}
void keyReleased(int keyCode)
{
repeat = false;
}