Slip19
Q1. Create a JSP page to accept a number from an
user and display it in words:
Example: 123 –
One Two Three. The output should be in red color.
number.jsp
<font
color='blue'>
<%
String
words[]={"Zero","One","Two","Three","Four","Five",
"Six","Seven","Eight","Nine"};
String s =
request.getParameter("no");
for(int i=0;i<s.length();i++){
out.print(words[s.charAt(i)-'0']+"
");
}
%>
</font>
number.html
<form
method='post' action='number.jsp'>
Number:<input
type='text' name='no'><br>
<input
type='submit'><input type='reset'>
</form>
Q2. Write a
Multithreading program in java to convert smile face into the crying face after
5 seconds and vice versa(Use Applet).
import
java.applet.Applet;
import
java.io.*;
import
java.awt.*;
import
java.util.*;
public
class Smile extends Applet implements Runnable
{
Thread
t;
int
x=0;
public
void run()
{
repaint();
}
public
void init()
{
Smile
s1=new Smile();
t=new
Thread(s1);
t.start();
setSize(500,500);
setBackground(Color.blue);
}
public
void paint(Graphics g)
{
if(x==0)
{
g.drawOval(40,40,130,130);
g.drawOval(57,75,20,20);
g.drawOval(110,75,20,20);
g.drawArc(60,110,80,40,180,180);
x=1;
}
else
if(x==1)
{
g.drawOval(40,40,130,130);
g.drawOval(57,75,20,20);
g.drawOval(110,75,20,20);
g.drawArc(60,110,80,40,-180,-180);
x=0;
}
try
{
Thread.sleep(2000);
}
catch(Exception
e)
{
e.printStackTrace();
}
repaint();
}
}
<html>
<body>
<applet
code="Smile.class" height=200 width=200>
</applet>
</body>
</html>