import java.awt.*; import java.applet.*; import java.net.*; public class Genie extends Applet { // Password string String password = new String ("Open sez me"); // Password label Label passwordPrompt = new Label ("Enter the password"); // Password hint label Label passwordHint = new Label ("(Password hint: " + password + ")"); // Password field TextField passwordField = new TextField (11); // Enter button Button enterButton = new Button ("Enter"); // Initialize my applet public void init () { // Set the background color setBackground (Color.white); // // Add all the GUI items // // Add the prompt objects add (passwordPrompt); // Add the password field add (passwordField); // Add the enter button add (enterButton); // Add the password hint add (passwordHint); } public boolean action (Event event, Object what) { // If the action was on the enter button if (event.target == enterButton) { // reset the card selection if (verifyPassword ()) { doSuccess (); } else { doFailure (); } } return true; } private void doSuccess () { try { // Genie file String genieFile = "Genie.html"; // Create a URL object for the Genie file URL geniePage = new URL (getCodeBase () + genieFile); // Switch the browser to the Genie page getAppletContext ().showDocument (geniePage); } catch (Exception exception) { // There shouldn't be any errors ;-) } } private void doFailure () { try { // Sorry file String sorryFile = "Sorry.html"; // Create a URL object for the sorry file URL sorryPage = new URL (getCodeBase () + sorryFile); // Switch the browser to the sorry page getAppletContext ().showDocument (sorryPage); } catch (Exception exception) { // There shouldn't be any errors ;-) } } public boolean verifyPassword () { // Get the password String userData = passwordField.getText (); // Check the password if (userData.equals (password)) { return true; } else { return false; } } }