home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-09-18 | 4.7 KB | 159 lines |
- /*
-
-
- password.java
-
-
- Made by John Eriksson 1997
-
-
-
-
-
- john_eriksson_sw@hotmail.com
-
-
-
-
-
- This code is free to use and modify!!!
-
-
-
-
-
-
-
-
- EXAMPLE HTML CODE:
-
-
- ------------------
-
-
-
-
-
- <center>
-
-
- <applet code="password.class" width=500 height=32>
-
-
- <param name=root value="http://www.myhomepage.com/secretfiles/">
-
-
- <param name=wrong value="http://www.myhomepage.com/secretfiles/wrong_pwd.html">
-
-
- <param name=color value="ffffff">
-
-
- <param name=textfield value="40">
-
-
- <param name=button value="Open">
-
-
- <param name=font_size value="12">
-
-
- <param name=font_face value="Courier">
-
-
- <param name=title value="Enter password:">
-
-
- </applet>
-
-
- <center>
-
-
-
-
-
- */
-
-
-
-
-
- import java.applet.*;
-
- import java.awt.*;
-
- import java.lang.*;
-
- import java.net.*;
-
- import java.io.*;
-
- import java.util.*;
-
-
-
- /*====================================================================================
-
- THE MAIN CLASS FOR THIS APPLET
-
- ====================================================================================*/
-
- public class password extends java.applet.Applet
-
- {
-
- private Button b_open;
-
- private TextField t_password;
-
- private Label l_title;
-
-
-
-
-
- private String root;
-
-
- private int col;
-
-
- private String title;
-
-
- private String buttontxt;
-
-
- private int bgcolor;
-
-
- private int fsize;
-
-
- private String fface;
-
-
- private String errorURL;
-
-
-
-
- /************************************************************************/
-
- /* Init the display */
-
- /************************************************************************/
-
- public void init()
-
- {
-
- int loop;
-
-
-
-
- String att = getParameter("root");
-
-
- root = (att == null) ? this.getDocumentBase().toString() : att;
-
-
- att = getParameter("textfield");
-
-
- col = (att == null) ? 20 : (Integer.valueOf(att).intValue());
-
-
- att = getParameter("font_size");
-
-
- fsize = (att == null) ? 11 : (Integer.valueOf(att).intValue());
-
-
- att = getParameter("font_face");
-
-
- fface = (att == null) ? "Arial" : att;
-
-
- att = getParameter("color");
-
-
- bgcolor = (att == null) ? Color.white.getRGB() : (Integer.parseInt(att, 16));
-
-
- att = getParameter("title");
-
-
- title = (att == null) ? "" : att;
-
-
- att = getParameter("button");
-
-
- buttontxt = (att == null) ? "OPEN" : att;
-
-
- att = getParameter("wrong");
-
-
- errorURL = (att == null) ? "" : att;
-
-
-
-
- setFont(new Font(fface, Font.PLAIN, fsize));
-
-
- setBackground(new Color(bgcolor));
-
-
-
-
- b_open = new Button(buttontxt);
-
-
- t_password = new TextField(col);
-
-
- l_title = new Label(title);
-
-
-
-
-
- t_password.setBackground(Color.white);
-
-
- t_password.setEchoCharacter('*');
-
-
-
-
-
- setLayout(new FlowLayout(FlowLayout.CENTER,3,3));
-
-
-
-
-
- if(title.length()>0)
-
-
- add(l_title);
-
-
-
-
-
- add(t_password);
-
- add(b_open);
-
-
-
-
-
- show();
-
- }
-
- /************************************************************************/
-
-
- /* Surf to error URL */
-
-
- /************************************************************************/
-
-
- void surfto_error()
-
-
- {
-
-
- if(errorURL.length()>0) {
-
-
- try {
-
-
- getAppletContext().showDocument(new URL(errorURL),"_self");
-
-
- }
-
-
- catch (MalformedURLException e) {}
-
-
- }
-
-
- else
-
-
- showStatus("Invalid password!");
-
-
- }
-
-
-
-
-
- /************************************************************************/
-
-
- /* Surf to an URL */
-
-
- /************************************************************************/
-
-
- void surfto()
-
-
- {
-
-
- if(t_password.getText().length()>0) {
-
-
- try{
-
-
- URL surftoURL = new URL(root+t_password.getText()+".html");
-
-
- InputStream in = surftoURL.openStream();
-
-
- int input = in.read();
-
-
- in.close();
-
-
- getAppletContext().showDocument(surftoURL,"_self");
-
-
- }
-
-
- catch (MalformedURLException e) { surfto_error(); }
-
-
- catch (SecurityException e) { surfto_error(); }
-
-
- catch (IOException e) { surfto_error(); }
-
-
-
-
-
- t_password.setText("");
-
-
- }
-
-
- }
-
-
-
- /************************************************************************/
-
- /* Handle all events */
-
- /************************************************************************/
-
- public boolean handleEvent(Event evt)
-
- {
-
-
-
-
- if(evt.id == Event.KEY_PRESS && evt.target == t_password && evt.key==10){
-
-
- surfto();
-
-
- return(true);
-
-
- }
-
-
- return super.handleEvent(evt);
-
- }
-
-
-
- /************************************************************************/
-
- /* Handle all actions */
-
- /************************************************************************/
-
- public boolean action(Event evt, Object arg)
-
- {
-
- if (evt.target == b_open) {
-
- surfto();
-
-
- return true;
-
- }
-
-
- return(super.action(evt,arg));
-
- }
-
- }
-
-
-
-