Many scripting languages like PHP give a better support to login forms, but when you are looking for a secure and more sophisticated login into your website we prefer the applet login it will make sure that you have enough securities and reliability.
The login for in the java is made using Abstract window Tool kit class by importing the packages of the awt(Abstract Window Toolkit) we also need to import the Applet class.
Finally we need to import the event class which generates the sessions or records the data the event package is sub packet of the awt package that must be imported into our program in order to work with the logins and generate events.
TheĀ init() function initializes the applet the objects are placed there and for theĀ UIĀ theĀ Paint() method to display User Interface to interact with on the client side
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | import java.awt.*; import java.applet.*; import java.awt.event.*; public class myapp extends Applet { TextField name,pass; Button b1,b2; public void init() { Label n=new Label("Name:",Label.CENTER); Label p=new Label("password:",Label.CENTER); name=new TextField(20); pass=new TextField(20); pass.setEchoChar('$'); b1=new Button("submit"); b2=new Button("cancel"); add(n); add(name); add(p); add(pass); add(b1); add(b2); n.setBounds(70,90,90,60); p.setBounds(70,130,90,60); name.setBounds(280,100,90,20); pass.setBounds(200,140,90,20); b1.setBounds(100,260,70,40); b2.setBounds(180,260,70,40); } public void paint(Graphics g) { repaint(); } } |
The output of the code will be like this
1 2 3 4 5 6 7 8 9 10 11 12 | STEP 1: Save the java Program as myapp.java Save the HTML code as myapp.html (Keep these two files in same directory) STEP 2: Compile using the command - javac myapp.java STEP 3: Run it using command - appletviewer myapp.html (OR) Double click on myapp.html |