A)
Write a JSP script to accept a String from a user and display it in reverse
order.
Answer :
Output :
B)
Write a java program in multithreading using applet for moving car.
Answer :
import java.applet.Applet;
import java.awt.*;
public class Slip30B extends Applet implements Runnable {
int x, z;
Thread t;
Image pic;
public void init() {
x = 50;
pic = getImage(getDocumentBase(), "./car.png");
t = new Thread(this);
t.start();
}
public void run() {
while (true) {
repaint();
x = x + 10;
if (x >= this.getWidth()) {
System.exit(0);
}
try {
Thread.sleep(100);
} catch (Exception e) {
}
}
}
public void paint(Graphics g) {
g.drawLine(0, 165, this.getWidth(), 165);
g.drawImage(pic, x, 120, this);
}
}
/*
* <applet code="Slip30B.java"
width="800" height="500">
* </applet>
*/
No comments:
Post a Comment