Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java Password box

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
dear all,
i have to put one link in one page sat one.htm, and i have to put password box to access onothere page say two.htm, please help me for the code for the same...

Thanks.
hiren
 
Here is some example code I used:

Label lblPassword;
TextField txtPassword;

lblPassword = new Label("Password:", Label.CENTER);
lblPassword.setFont(new Font("Serif", Font.BOLD, 18));
lblPassword.setForeground(Color.black);
txtPassword = new TextField("", 8);
txtPassword.setEchoChar('*');
txtPassword.setBackground(Color.white);
txtPassword.setForeground(Color.blue);
txtPassword.setFont(new Font("Serif", Font.BOLD, 18));

PasswordEvent PasswordHandler = new PasswordEvent();
txtPassword.addActionListener(PasswordEvent);

You will need to make an inner class to handle the event.
That would be a class PasswordEvent.
In the method actionPerformed put code to instantiate another Frame and have that be viewed if the hidden password is correct.

Notice, if you are using Swings, there is a JPasswordField class which inherits from JTextField. It is a great class which has a lot more methods to use.

This should get you started.

Brian

 
thanks a lot brian it is really working and even i have done many modification,,, thanks again...


hiren, india.
 
dear brian,
what you have sent is for VB only, and I think that shold contain Java Script header, but you have not decided the same ,so haw can it be directly connected through htm? without spoiling single htm page.
 
NO, the sample code I gave you is in pure Java and not VB.

Visual Basic is a totally different programming language. A completely different animal.

Here is sample code on how to call a second html form from your Java applet.

You should look up these classes and methods to become familar with their features. You need to build a URL object that contains the path for your second html page. Then use the Applet showDocument() method.

import java.applet.*; // need to declare for context.
private AppletContext context; // html document for applet.

{
try // call URL for Servlet to get HTML page.
{
URL hostURL = getCodeBase(); //path to html page.
URL newURL = new URL(hostURL, "yourHTML.html");
// log("newURL: " + newURL);
context.showDocument(newURL);
}
catch (MalformedURLException e)
{
log(e.toString());
}
}

public log(String msg)
{
System.out.println(msg);
}

Try this and see if it works.

Brian (Sun Certified Programmer on the Java 2 Platform)
 
Hi Brian,

FYI, there is this class JPasswordField. Although it is roughly the same as setting echo, but I guess since there is a ready class for us to use, why not?? :)

Regards,
Leon If you need additional help, you can email to me at zaoliang@hotmail.com I don't guaranty that I will be able to solve your problems but I will try my best :)
 
Yes, I know LeonTang,

I mentioned that above and it is a swing GUI class. I use it all the time and I prefer it. I don't know what Hiren is using AWT or SWING GUI? They should never be mixed. One or the other. Also, you will need a Plug in from SUN if you are using Swings in Applets. The Browsers do not support the latest versions of Java 2 and you have to override it. This can be annoying to users because the first time the applet html page is loaded, it prompts them to download and install the Plug-IN. With AWT you do not have to do that. The Swing components are light weight. Excellent GUI Classes that are written by Sun in PURE Java.

AWT GUI classes are heavey weight classes that are tied to the native machine that the JVM is running on.

Brian
(Sun Certified Programmer on the Java 2 platform)
(Java & OOP Instructor)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top