Results 1 to 2 of 2
  1. #1
    the swan is offline Member
    Join Date
    Mar 2009
    Posts
    7
    Rep Power
    0

    Default what's the wrong in this Code

    hi
    i wana to insert name and Pwd and when i check them if name and pwd ok
    another form will opend

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JPasswordField;
    import javax.swing.JTextField;
    
    
    
    public class A extends JFrame implements ActionListener
    {
    	
    	JTextField AdminNa;
    	JPasswordField AdminPwd;
    	JButton chkAdmin;
    	
    	public A()
    	{
        Container mainContaner=getContentPane();
    	mainContaner.setLayout(new BorderLayout());        
    	//passengerClass p=new passengerClass();
    	
    	JPanel  MainPanCard=new JPanel();
    
    	CardLayout AddCardLout=new CardLayout();
    	
    	
    	JLabel LAdmin=new JLabel(" Name",JLabel.CENTER);
    	JTextField AdminNa=new JTextField(15);
    	JLabel LAdminPwd=new JLabel(" PassWord",JLabel.CENTER);
     	JPasswordField AdminPwd=new JPasswordField(15);
     	JButton chkAdmin=new JButton("Check");
     	chkAdmin.addActionListener(this);
     	
     
    			MainPanCard.add(LAdmin);
    			MainPanCard.add(AdminNa);
    			MainPanCard.add(LAdminPwd);
    			MainPanCard.add(AdminPwd);
    			MainPanCard.add(chkAdmin);
     	
     	JLabel CreatedBy=new JLabel("created by  mohammed",JLabel.CENTER);
     	JLabel YARS=new JLabel(" Airlines Reservation System");
     JPanel  footer_pan=new JPanel();
     	JPanel  header_pan=new JPanel();
     	footer_pan.setBackground(new Color(30,200,199));
     	header_pan.setBackground(new Color(30,200,199));
     	//MainPanCard.setLayout(AddCardLout);
     	mainContaner.add(MainPanCard,BorderLayout.CENTER);
        mainContaner.add(CreatedBy,BorderLayout.SOUTH);
        
     	footer_pan.add(CreatedBy);
        mainContaner.add(footer_pan,BorderLayout.SOUTH);
        header_pan.add(YARS);
        mainContaner.add(header_pan,BorderLayout.NORTH);
        
        //mainContaner.
     	setSize(400, 400);
        setVisible(true);	
    	}
    	
    	
        public void actionPerformed(ActionEvent e)
        {
        	if (e.getSource()==chkAdmin)
        	{
        		if((AdminNa.getText()=="rrr")&& (AdminPwd.getText()=="2344"))
        		
        		System.out.println("sdfsdfsfsfsdf");
        		else
        			JOptionPane.showMessageDialog(this,"Try again","result", JOptionPane.INFORMATION_MESSAGE);
        	}
    
        }
        	
        
    	//}
    
    
    	
    	public static void main(String[] arg)
    	   {
    	    	A Achk = new A();
    	        Achk.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);	
    	        
    	 
    	   }
    	
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    what does your current code do and / or not do?

    edit: one error you are doing is to compare Strings with the == operator:
    Java Code:
    if (AdminNa.getText()=="rrr"
    The == operator checks to see if Object A is the same object as Object B and that is not what you want to know here. You don't care if the two Strings are the same object, but rather you want to check to see if both Strings contain the same characters. To do this, use the equals or equalsIgnoreCase method:
    Java Code:
    if (AdminNa.getText().equals("rrr") //...
    Last edited by Fubarable; 04-04-2009 at 04:33 AM.

Similar Threads

  1. what's wrong with my code? please help me...
    By lovely23 in forum Java Applets
    Replies: 2
    Last Post: 03-01-2009, 01:33 PM
  2. pls tell wat wrong with my code???
    By low224 in forum New To Java
    Replies: 13
    Last Post: 01-11-2009, 07:40 AM
  3. what's wrong with this code?
    By agenteleven in forum Advanced Java
    Replies: 5
    Last Post: 10-07-2008, 11:26 AM
  4. what is wrong with this code
    By masaka in forum New To Java
    Replies: 5
    Last Post: 04-16-2008, 08:27 AM
  5. What's wrong with this code?
    By Wizard wusa in forum New To Java
    Replies: 14
    Last Post: 01-22-2008, 11:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •