rendered paste bodyimport java.applet.*;
import java.awt.event.*;
import java.awt.*;
public class Main extends Applet implements KeyListener
{
Graphics bufferGraphics;
Image offscreen;
int appWidth = 500;
int appHeight = 500;
int squareX = (appWidth / 2) - 20;
int squareY = (appHeight / 2) - 20;
Image back;
public void init()
{
back = getImage(getDocumentBase(),"bg.jpg");
addKeyListener(this);
offscreen = createImage(appWidth,appHeight);
bufferGraphics = offscreen.getGraphics();
setSize(appWidth,appHeight);
}
public void paint(Graphics g)
{
bufferGraphics.clearRect(0,0,appWidth,appWidth);
bufferGraphics.drawImage(back,0,0,this);
bufferGraphics.setColor(Color.red);
bufferGraphics.drawString("Cursed Testing",((appWidth / 2) - 50),10);
bufferGraphics.fillRect(squareX,squareY,20,20);
g.drawImage(offscreen,0,0,this);
requestFocus();
}
public void update(Graphics g)
{
paint(g);
}
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeycode();
if (keyCode == e.VK_RIGHT) {
if (e.isShiftDown())
squareX += 10;
else
squareX++;
}
if (keyCode == e.VK_LEFT) {
if (e.isShiftDown())
squareX -= 10;
else
squareX--;
}
if (keyCode == e.VK_UP) {
if (e.isShiftDown())
squareY -= 10;
else
squareY--;
}
if (keyCode == e.VK_DOWN) {
if (e.isShiftDown())
squareY += 10;
else
squareY++;
}
}
repaint();
}
public void keyReleased(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
}
}