5 Replies - 27947 Views - Last Post: 20 October 2007 - 03:42 AM Rate Topic: -----

#1 anjali_gargcs   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 19-October 07

AWT LOGIN PROGRAM

Posted 19 October 2007 - 07:32 AM

public void actionPerformed(ActionEvent ae)
 {
  if(ae.getSource()==b1)
  {
   if(t1.equals("anjali") && t2.equals("abc"))
   {	 
		f1=new Frame("Already Registered");
		f1.setBounds(50,50,200,200);
		f1.setBackground(Color.cyan);
		 f1.show();

		  Label l3=new Label("You are authenticated");
		  l3.setForeground(Color.red);
		  l3.setBounds(50,50,150,150);
		  f1.add(l3);
		   f1.addWindowListener(new WindowAdapter()
				{
						public void windowClosing(WindowEvent e)
						{
								f1.dispose();
								}
						});
   }
   else
   {
	   f1=new Frame("Not Registered?");
		f1.setBounds(50,50,200,200);
		f1.setBackground(Color.cyan);
		 f1.show();

		  Label l3=new Label("You are not authenticated");
		  l3.setForeground(Color.red);
		  l3.setBounds(50,50,150,150);
		  f1.add(l3);
		   f1.addWindowListener(new WindowAdapter()
				{
						public void windowClosing(WindowEvent e)
						{
								f1.dispose();
								}
						});
   }
 }


In this progarm i want to make a login program by using AWT. here i want that if user name is anjali and password is abc then it shoul be authenticated.otherwise not.
but is giving not authenticated in both the condition.
plz help
me
i also attached full program plz see and give me reply soon
Thanks

*edit: added code tags, next time please use them -1lacca

Is This A Good Question/Topic? 0
  • +

Replies To: AWT LOGIN PROGRAM

#2 1lacca   User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: AWT LOGIN PROGRAM

Posted 19 October 2007 - 07:43 AM

What are t1 and t2? If they are some kind of a text field, then probably you have to take their value (getText()) and use equals on them.
Was This Post Helpful? 0
  • +
  • -

#3 anjali_gargcs   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 19-October 07

Re: AWT LOGIN PROGRAM

Posted 19 October 2007 - 07:53 AM

View Post1lacca, on 19 Oct, 2007 - 07:43 AM, said:

What are t1 and t2? If they are some kind of a text field, then probably you have to take their value (getText()) and use equals on them.



ya these are text field i have used getText method
just min
i am showing full program to u

import java.awt.*;
import java.awt.event.*;

class ExUser extends Frame implements ActionListener
{
				Frame f1,f2,f3;
				Panel p1,p2;
				Label l1,l2;
				TextField t1,t2;
				Button b1,b2,b3;
		ExUser()
		{
				super("Example for Using GridLayout");

				setBounds(50,50,300,300);
				setLayout(new GridLayout(1,2));



				p1 = new Panel();
				p2 = new Panel();


				p1.setLayout(new FlowLayout(0));
				p2.setLayout(new FlowLayout(2));


				p1.setBackground(Color.magenta);
				p2.setBackground(Color.pink);

				l1 = new Label("User Name");
				 t1 = new TextField(20);
				l2 = new Label("Password");
				t2 = new TextField(10);

				b1 = new Button("Ok");
				b2 = new Button("Cancel");
				b3=new Button("New User");


				b1.addActionListener(this);
				b2.addActionListener(this);
				b3.addActionListener(this);

				p1.add(l1);
				p1.add(t1);
				p1.add(l2);
				p1.add(t2);

				p1.add(b1);
				p1.add(b2);
				p2.add(b3);

				add(p1);
				add(p2);

				t1.getText();
				t2.setEchoChar('*');
				show();
				  addWindowListener(new WindowAdapter()
				{
						public void windowClosing(WindowEvent e)
						{
								dispose();
								}
						});

		}
		public void actionPerformed(ActionEvent ae)
 {
  if(ae.getSource()==b1)
  {
   if(t1.equals("anjali") && t2.equals("abc"))
   {	 
		f1=new Frame("Already Registered");
		f1.setBounds(50,50,200,200);
		f1.setBackground(Color.cyan);
		 f1.show();

		  Label l3=new Label("You are authenticated");
		  l3.setForeground(Color.red);
		  l3.setBounds(50,50,150,150);
		  f1.add(l3);
		   f1.addWindowListener(new WindowAdapter()
				{
						public void windowClosing(WindowEvent e)
						{
								f1.dispose();
								}
						});
   }
   else
   {
	   f1=new Frame("Not Registered?");
		f1.setBounds(50,50,200,200);
		f1.setBackground(Color.cyan);
		 f1.show();

		  Label l3=new Label("You are not authenticated");
		  l3.setForeground(Color.red);
		  l3.setBounds(50,50,150,150);
		  f1.add(l3);
		   f1.addWindowListener(new WindowAdapter()
				{
						public void windowClosing(WindowEvent e)
						{
								f1.dispose();
								}
						});
   }
 }


now plz tell me what is the problem with it
Was This Post Helpful? 0
  • +
  • -

#4 1lacca   User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: AWT LOGIN PROGRAM

Posted 19 October 2007 - 08:12 AM

Please, use those code tags, because this way we have to add them, and you'll get your answers later.

Anyway, I think you don't use the getText appropriately, I mean they are clearly missing here:
   public void actionPerformed(ActionEvent ae)
{
  if(ae.getSource()==b1)
  {
   if(t1.equals("anjali") && t2.equals("abc"))


The condition should look like this:
 if(t1.getText().equals("anjali") ...


Was This Post Helpful? 0
  • +
  • -

#5 anjali_gargcs   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 19-October 07

Re: AWT LOGIN PROGRAM

Posted 20 October 2007 - 03:03 AM

View Post1lacca, on 19 Oct, 2007 - 08:12 AM, said:

Please, use those code tags, because this way we have to add them, and you'll get your answers later.

Anyway, I think you don't use the getText appropriately, I mean they are clearly missing here:
   public void actionPerformed(ActionEvent ae)
{
  if(ae.getSource()==b1)
  {
   if(t1.equals("anjali") && t2.equals("abc"))


The condition should look like this:
 if(t1.getText().equals("anjali") ...




Thank you so much
Was This Post Helpful? 0
  • +
  • -

#6 1lacca   User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: AWT LOGIN PROGRAM

Posted 20 October 2007 - 03:42 AM

You are welcome.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1