ADD CODE: MOVE ZOMBIE W/ ARROW KEYS CONTINUOUSLY. EX: IF IT IS UP, IT MUST CONTINUE UP EVEN W/ 1 CLICK UNLESS YOU CLICK ANOTHER ARROW KEY.
public class j extends java.applet.Applet implements Runnable {
Image z[] = new Image [2];
Image crImg;
Thread r;
int x;
int y;
public void init() {
String zSrc[] = {"z1.png", "z2.png",};
for (int i = 0; i < zombies.length; i++) {
z[i] = getImage(getCodeBase(), "images/" + zSrc[i]); }}
public void start() {
if (r == null) {
r = new Thread(this);
r.start();}}
public void stop() {
if (r != null) {
r.stop();
r = null;}
void pause (int time) {
try { Thread.sleep(time); }
catch (InterruptedException e) { }}
public void run() {
walk (0, size().width); }
void walk (int start, int end) {
for (int i = start; i < end; i += 1) {
x = i;
if (crImg == zombies[0])
crImg = zombies[1];
else crImg = zombies[0];
repaint();
pause(150);}
public void paint(Graphics g) {
if (crImg != null)
g.drawImage(crImg, x, y, width, height, this);}
Applet is an outdated technology.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class EventApplet extends Applet implements ActionListener{
Button b;
TextField tf;
public void init(){
tf=new TextField();
tf.setBounds(30,40,150,20);
b=new Button("Click");
b.setBounds(80,150,60,50);
add(b);add(tf);
b.addActionListener(this);
setLayout(null);
}
public void actionPerformed(ActionEvent e){
tf.setText("Welcome");
}
}
https://www.javatpoint.com/Event-Handling-in-applet
Comments
Leave a comment