Results 1 to 16 of 16
  1. #1
    rithish is offline Member
    Join Date
    Apr 2011
    Posts
    39
    Rep Power
    0

    Default login action to anotherform swing

    in swing i want to create login form whenerver i click button it should to go to another form please give a coding for this or please look at the view of my coding that is below
    Java Code:
    import javax.swing.*;
    
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    
    
    public abstract class login  extends JFrame implements ActionListener {
      public static void main(String[] args) {
    
    	  
    	  JTextField    firstField = new JTextField(10);
        JPasswordField middleField = new JPasswordField(10);
                      JButton b1=new JButton("ok");
                       
        
        JLabel firstLabel = new JLabel("username", JLabel.RIGHT);
        firstLabel.setDisplayedMnemonic('F');
        firstLabel.setLabelFor(firstField);
        
    
        JLabel middleLabel = new JLabel("password", JLabel.RIGHT);
        middleLabel.setDisplayedMnemonic('I');
        middleLabel.setLabelFor(middleField);
        
      
      
           
        
        JPanel p = new JPanel( );
        p.setLayout(new GridLayout(3, 2, 5, 5));
        p.add(firstLabel);
        p.add(firstField);
        p.add(middleLabel);
        p.add(middleField);
       p.add(b1);
       b1.addActionListener(this);
    
    
        JFrame f = new JFrame("login");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setContentPane(p);
        f.pack( );
       f.setVisible(true);
       
      public void actionperformed(ActionEvent e)  
      {
    	
    	 Object firstField;
    	Object middleField;
    	if((firstField.equals("r"))&&middleField.equals("r"))
    	 {
    		 Object b1;
    		if((e.getSource()==b1))
    		 {
    			 
    			 
              form  form1=  new form();
    	
    			 
    		 }
    	  
    	  
      }
      }
     
      
      }
      
      
    }
    
    
    
    2nd 
    
    
    
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JRadioButton;
    
    
    public abstract class form extends JFrame implements ActionListener{
    	
    	
    	form()
    	{
    		JFrame f1=new JFrame();
    		JRadioButton r1=new JRadioButton("candidate");
    		   JRadioButton r2=new JRadioButton("public"); 
    		   JButton b2=new JButton("ok");
    		    JPanel p1=new JPanel();
    		    p1.setLayout(new GridLayout(3,2,5,5));
    		     p1.add(r1);
    		     p1.add(r2);
    		     p1.add(b2);
    		     f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		     f1.setContentPane(p1);
    		     f1.pack();
    		    f1.setVisible(true);
    		    r1.addActionListener(this);
    		    r2.addActionListener(this);
    		    b2.addActionListener(this);
    		    f1.setVisible(true);
    		   
    		    public actionperformed(ActionEvent e){
    		    	
    		    	
    		    	if((e.getSource()==r1)&&(e.getSource()==b2))
    		    	{
    		    		candidate1 can=new candidate1();
    		    		
    		    	}
    		    	else
    		    		if((e.getSource()==r2) && (e.getSource()==b2))
    		    		{
    		    			public1 pub=new public1();
    		    			
    	
    		    		}
    		    	
    		    }
    		    
    		    
    	}
    
    }
    Last edited by rithish; 04-20-2011 at 08:21 PM.

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    6

    Default

    Quit cluttering the forum with 3 postings on the same topic.

    Use the "Code" tags when posting code to the code is readable. You can Edit your posting and replace the code.

  3. #3
    rithish is offline Member
    Join Date
    Apr 2011
    Posts
    39
    Rep Power
    0

    Default sorry

    iam new sir please what is "code" tag????

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    6

    Default

    Find the appropriate button (icon) in the editor window. Its just like using the "Bold" or "Italic" button.

  5. #5
    rithish is offline Member
    Join Date
    Apr 2011
    Posts
    39
    Rep Power
    0

    Default

    now i understood sir

  6. #6
    rithish is offline Member
    Join Date
    Apr 2011
    Posts
    39
    Rep Power
    0

    Default

    sir help me

  7. #7
    RichersooN is offline Senior Member
    Join Date
    Jan 2011
    Location
    Rizal Province, Philippiines
    Posts
    167
    Rep Power
    0

    Default

    You coding of your program is really bad why?
    #1 The name of the variable is the same as in outside, like your textfields
    #2 You make the textfield as an object(Whats the point? )
    Java Code:
    I THINK IT'S BETTER IF:
    .
    .
    //transfer all the information from class1 to class2
    .
    .
    class2.setVisible(true);

  8. #8
    rithish is offline Member
    Join Date
    Apr 2011
    Posts
    39
    Rep Power
    0

    Unhappy correction

    ok sir what s the lead sir now where should i correct

  9. #9
    RichersooN is offline Senior Member
    Join Date
    Jan 2011
    Location
    Rizal Province, Philippiines
    Posts
    167
    Rep Power
    0

    Default

    You should use getters and setters to transfer all the data from class1 to class2

    if you don't know how to do it, you should learn the fundamentals ^_^ you're not ready for intermediate topics yet

  10. #10
    rithish is offline Member
    Join Date
    Apr 2011
    Posts
    39
    Rep Power
    0

    Default

    ok if i make class1 object.setvisible(true);.will it make correct

  11. #11
    RichersooN is offline Senior Member
    Join Date
    Jan 2011
    Location
    Rizal Province, Philippiines
    Posts
    167
    Rep Power
    0

    Default

    WHAT IS that OBJECT?
    Cant it be like this?:
    Java Code:
    class1{
    .
    .
    .
             class2.setVisible(true);
    .
    .
    .
    }
    I THINK WITH YOUR CODE IT WILL ONLY MAKE THE class2 appear but no data from class1

  12. #12
    rithish is offline Member
    Join Date
    Apr 2011
    Posts
    39
    Rep Power
    0

    Default

    thank u very much sir

  13. #13
    rithish is offline Member
    Join Date
    Apr 2011
    Posts
    39
    Rep Power
    0

    Default

    ok if i use a get method should i use a return value

  14. #14
    rithish is offline Member
    Join Date
    Apr 2011
    Posts
    39
    Rep Power
    0

    Default eclipse problem

    b1.addactionlistener(this);
    shows error in eclipse how to solve this

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

    Default

    Quote Originally Posted by rithish View Post
    b1.addactionlistener(this);
    shows error in eclipse how to solve this
    You appear to have several threads in the forum covering the same subject -- why? Are you trying to annoy us? Please don't do this.

    Regarding your question -- how can we answer it when we don't see your error message or any context?

  16. #16
    rithish is offline Member
    Join Date
    Apr 2011
    Posts
    39
    Rep Power
    0

    Default

    extremely sorry sir iam new to this .i dont know how to use this

Similar Threads

  1. login action to anotherform
    By rithish in forum AWT / Swing
    Replies: 3
    Last Post: 04-21-2011, 05:36 AM
  2. login action to anotherform
    By rithish in forum SWT / JFace
    Replies: 1
    Last Post: 04-21-2011, 03:11 AM
  3. Replies: 10
    Last Post: 04-02-2011, 11:06 PM
  4. Java Swing Login Form
    By sehudson in forum Advanced Java
    Replies: 5
    Last Post: 06-01-2010, 11:53 AM
  5. Replies: 7
    Last Post: 04-21-2009, 06:00 AM

Posting Permissions

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