Исходный файл NotePad.java(новый файл):
/** *<applet code = "NotePad.class" width=350 height=150></applet> */
//This is the fifth programm for the examination //It is made by SomeBody and modified by VILenin (with the help of Arty)
import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.util.Hashtable;
public class NotePad extends Applet implements ActionListener { Hashtable setofnames;
Label nameLabel; Label phoneLabel;
TextField nameField; TextField phoneField;
Button addormodifyButton; Button findButton;
public void init() { setLayout(null);
nameLabel = new Label("Name: "); nameLabel.setBounds(10,10,50,20); add(nameLabel);
phoneLabel = new Label("Phone: "); phoneLabel.setBounds(10,40,50,20); add(phoneLabel);
nameField = new TextField(); nameField.setBounds(80,10,240,25); add(nameField);
phoneField = new TextField(); phoneField.setBounds(80,40,240,25); add(phoneField);
addormodifyButton = new Button ("Add or Modify "); addormodifyButton.setBounds(10,80,150,30); add(addormodifyButton);
findButton = new Button("Find "); findButton.setBounds(170,80,150,30); add(findButton);
setofnames = new Hashtable();
addormodifyButton.addActionListener(this); findButton.addActionListener(this); }
public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == addormodifyButton) { onAddormodify(); nameField.setText(""); phoneField.setText(""); } else if (source == findButton) { onFind(nameField.getText()); nameField.setText(""); } }
void onAddormodify() { String str = (String)setofnames.put(nameField.getText(),phoneField.getText()); }
void onFind(String name) { String str = (String) setofnames.get(name); if (str == null) { phoneField.setText("Sorry, I don't know :("); } else { phoneField.setText(str); } } }