// Filename: Vi.java
// Purpose: To simulate vi editor movements.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Vi extends Applet implements KeyListener
{ int height, width;
int x, y;
String marker = "[]";
public void init()
{ width = getSize().width;
height = getSize().height;
setBackground(Color.black);
x = width / 2;
y = height / 2;
addKeyListener(this);
}
public void keyPressed(KeyEvent e) {}
public void keyReleased(KeyEvent e) {}
public void keyTyped(KeyEvent e)
{ char c = e.getKeyChar();
if(c != KeyEvent.CHAR_UNDEFINED)
{ if(c == 'h') {x = x - 5;}
else if(c == 'j') {y = y + 5;}
else if(c == 'k') {y = y - 5;}
else if(c == 'l') {x = x + 5;}
else {}
repaint();
e.consume();
}
}
public void paint(Graphics g)
{ g.setColor(Color.green);
g.drawString(marker, x, y);
}
}