// FirstForm Class by Susan A-F // Standard imports for applets import java.awt.*; import java.awt.event.*; // seemingly not in 1.0 import java.applet.*; import javax.swing.*; public class FirstForm extends Applet implements ActionListener { // put class member data (properties) here private Label namePrompt = new Label("Tell me your name"); private JTextField nameField = new JTextField(20);; // private JButton myButton = new JButton("Click me"); private String message = "(Who are you anyway?)"; private static String greeting = "How are you today?"; private Font font = new Font("Times New Roman", Font.BOLD, 20); private int green = 0; //used to vary color of greeting private String [] questions = { "How are you today?", "Nice weather we're having.", "Did you sleep well?", "Nighty night, sleep tight", "Whatcha gonna do today?" }; // override Applet methods init() and paint() public void init() { // add components to the applet's panel add(namePrompt); add(nameField); nameField.addActionListener(this); // listen for actions here // this means the Applet } // end init public void paint(Graphics g) { // Choose a font and color, for our Graphics object g.setFont(font); g.setColor(new Color(255,green,20)); // red g.drawString(message,1,60); // actual writing happens here g.setColor(new Color(30,green, 255)); // blue green += 25; // add more green green %= 256; int i = (int) Math.floor(Math.random()*questions.length); g.drawString(questions[i],1,90); nameField.repaint(); } // override the TextListener method textValueChanged() public void actionPerformed(ActionEvent e) { /* There is only one event, the change of namefield When this happens, we want to copy the new value into message, then call repaint() to force paint() (above) to write the new value */ String name = nameField.getText(); message = "Glad to meet you, " + name; nameField.setText(""); // erase entry repaint(); } } // end class FirstForm