hello, i need to create an applet for a "company", in which you log in, and according to your possition(ex: worker, manager) you can see and change different objects such as sallery and the abililty to fire people. im completely stuck on the login part, i have the gui set up but i can't figure out how to get myself to login. this is what i have thus far.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.io.*;

public class driver extends JApplet
{
	private ButtonListener listener;
	private JButton btnLogin;
	private JTextField txtUser;
	private JPasswordField txtPass;
	private JLabel lblAccepted;
	public String User, Pass;



	public void init()
	{
		Container cp = getContentPane();
		cp.setLayout(new FlowLayout());
		listener = new ButtonListener();
		txtUser = new JTextField("Username");
		txtPass = new JPasswordField("Password");
		btnLogin = new JButton("Login");
		btnLogin.addActionListener(listener);
		lblAccepted = new JLabel();
		txtUser.setColumns(10);
		txtPass.setColumns(10);
		txtPass.setEchoChar('*');

		cp.add(txtUser);
		cp.add(txtPass);
		cp.add(btnLogin);
		cp.add(lblAccepted);
	}



	public class ButtonListener implements ActionListener
	{
		public void actionPerformed(ActionEvent event)
		{
			Object source = event.getSource();


			if (source==btnLogin)
			{
				User = new String(txtUser.getText());
				Pass = new String(txtPass.getPassword());

				
				


			}


		}

	}

}

any help would be much appreciated.

Can you tell me the architecture of the system ??

And how do you plan to validate users ??? Do you have a central database server or is it small school / college assignment where your database will be MS Access / etc and it will reside on the machine where the applet is running ??

Are you planning to connect the applet to a database on the server ?
Provide more details so that we can help you.

I agree with stephen84s, you need some sort of overall view of how the different parts of your system pull together.

Generally if you have an applet, it would probably have to communicate with a server that would fulfil requests such as user authentication. It would communicate with the server by means of a socket and the server would understand the communication because you would have programmed the server. I'm not sure if you already know this but I just thought I'd make a suggestion.

If what I explained is what you were uncertain about then let us know and we'll explain it further. Oh there are other ways to do this but what I described is probably the easiest and most used (client-server architecture). It's especially useful when you have multiple applets loaded from various sites. Alternatively you could create a dynamic web project... probably more flexible than an applet.

im going to have the users/passwords stored in the program, no securty or anything is needed, its a small school project. So that if the username textfiend and password fields have the correct information it shows you a new page in which your work status decides what you see and not.

Ah well then doesn't that answer your question about logging in? Comparing input with predefined values in your program seems perfectly acceptable for your application. I guess what you want to know is how to change from the log in screen to the content/menu screen?

What you could do is have multiple panels on your applet and make them visible in correspondence to who logs in. In that way, when a worker enters his details correctly, the log in screen is made invisible and the worker screen is made visible. Not the most elaborate solution but rather simple don't you think? Perhaps you should disable the panel when you make it invisible... and enable it when made visible.

Hope this makes sense, otherwise give us a shout.

This article has been dead for over six months. Start a new discussion instead.