import java.awt.event.*;
import java.awt.*;
import java.applet.Applet;
public class Applet1 extends Applet implements ActionListener
{
Label s;
TextField input;
Button btn;
public void init()
{
s = new Label("pls input an alphabet:");
input = new TextField(4);
btn = new Button("confirm");
add(s);
add(input);
add(btn);
btn.addActionListener(this);
}
public void paint(Graphics g)
{
int n = 0;
char c = ' ';
String s = input.getText(); // read a String, not character
if (!"".equals(s))
{
c = s.charAt(0); // take the first character
n = (int) c;
}
if (n >= 97 && n <= 122)
{
n = 122 - (n - 97);
c = (char) n;
g.drawString("response alphabet:" + c, 200, 200);
}
else if (c >= 65 && c <= 90)
{
n = 90 - (n - 65);
c = (char) n;
g.drawString("response alphabet:" + c, 200, 200);
}
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == btn)
{
repaint();
}
}
}