can somebody help me to put an action in a button that comes from a different class. Specifically t

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



 class LogIn implements ActionListener
{

	private JFrame f,f2;
	private JButton jLog, jCan, jReg,jOk;
	private JPanel j1, j2, j3, j4,j5,j6;
	private JTextField jText;
	private JPasswordField jPass;
	private JLabel user, pass;

	public LogIn()
	{
		f = new JFrame("Log-In");
                f2= new JFrame("Info");

                jLog = new JButton("Log-In");
		jCan  = new JButton("Cancel");
		jReg = new JButton("Sign-up");
                jOk= new JButton("Ok");

                jLog.addActionListener(this);
		jCan.addActionListener(this);
		jReg.addActionListener(this);
                jOk.addActionListener(this);


		j1 = new JPanel();
		j2 = new JPanel();
		j3 = new JPanel();
		j4 = new JPanel();
                j5= new JPanel();
                j6=new JPanel();



		jText = new JTextField(15);
		jPass = new JPasswordField(15);

		user = new JLabel("Username");
		pass = new JLabel("Password");

	}

	public void launch()
	{
		j1.setLayout(new FlowLayout());
		j1.add(user);
		j1.add(jText);

		j2.setLayout(new FlowLayout());
		j2.add(jLog);
		j2.add(jCan);

		j3.setLayout(new FlowLayout());
		j3.add(pass);
		j3.add(jPass);

		j4.setLayout(new FlowLayout());
		j4.add(jReg);

		
                
         



                f.setLayout(new GridLayout(4,1));
		f.add(j1);
		f.add(j3);
		f.add(j2);
		f.add(j4);
		f.setVisible(true);
		f.pack();
		f.setLocation(250,250);

               //INFO FRAME
                f2.setSize(300,600);

                //f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}




        public void actionPerformed (ActionEvent event)
	{





  //sign up

		if(event.getActionCommand().equals("Sign-up"))
		{
			f.setVisible(false);
			regForm rg = new regForm();
			rg.launch();
		}



//lOGIN button

		else if(event.getActionCommand().equals("Log-In"))
		{

			try{

			String get1 = jText.getText();
			String get2 = jPass.getText();

			FileReader fr = new FileReader("D:/Project/"+  get1 +".txt");

			BufferedReader in = new BufferedReader(fr);
			String str1, str2;

				str1 = in.readLine();
				str2 = in.readLine();


			if((str1.equals(get1)) && (str2.equals(get2)))
			{
				//
                            //System.out.print("Success");

                            /*f.dispose();
                            regForm rg = new regForm();


                            rg.launchs();*/
                       

			}


                        else
			{
				
			}
				}

			catch(FileNotFoundException e)
			{
				System.out.print("not found"); //
			}
			catch(IOException e)
			{
				System.out.print("not found");
			}
 
		}


     // CANCEL BUTTON
                   
                 /*if(event.getActionCommand().equals("Cancel")){
                 f.dispose();*/

                }
                
                                 
}


//DECLARATIONS -ACTION LISTENER
class regForm implements ActionListener
{
	private JFrame f,f2;
	private JButton jSub,jOk;
	private JPanel j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12,j13,j14;
	private JPasswordField jPass, jConfirm;

	private JTextField jName, jLast, jUser, jEmail, jContact,
				jMonth, jYear, jDay, jAdd ;

	private JLabel user, pass, confirm, name, email, contact,
			 gender, title, bday, address, select;

	private JRadioButton m, fem;
	private ButtonGroup bg;
        private JComboBox combo;

        private JComboBox combo1;
        private JComboBox combo2;
         
      private String s;
         
 //FRAME

        public regForm()
	{

		f = new JFrame("Registration Form");
                f2=new JFrame("");
//Labels
		title = new JLabel("PERSONAL INFORMATION", JLabel.CENTER);
		name = new JLabel("Name: ");
		gender = new JLabel("Gender: ");
		bday = new JLabel("Birthday: ");
		email = new JLabel("Email Address: ");
		contact = new JLabel("Contact Number: ");
		user = new JLabel("Username: ");
		pass = new JLabel("Password: ");
		confirm = new JLabel("Confirm Password: ");
		address = new JLabel("Address: ");
		select = new JLabel("CHOOSE YOUR USERNAME AND PASSWORD" , JLabel.CENTER);

		title.setForeground(Color.darkGray);
		title.setFont(new Font("Arial Black", Font.BOLD, 15));
		select.setForeground(Color.black);
		select.setFont(new Font("Calibri", Font.BOLD, 15));
//Text Fields

		jName = new JTextField("First Name",10);
		jLast = new JTextField("Last Name", 10);
		jMonth = new JTextField("MM", 2);
		jDay = new JTextField("DD", 2);
		jYear = new JTextField("YEAR", 4);
		jContact = new JTextField(10);
		jUser = new JTextField(10);
		jEmail =  new JTextField(10);
		jAdd = new JTextField(10);

		jDay.setForeground(Color.gray);
		jMonth.setForeground(Color.gray);
		jYear.setForeground(Color.gray);

 //DROPDOWN BOXES


       String[] comboStrings = { "January", "February", "March", "April", "May","June","July","August","September","October","November","December" };
       String[] comboStrings1= {"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","21","22","23","24","25","26","27","28","29","30","31",};
       String[] comboStrings2={"1960","1962","1963","1964","1965","1966","1967","1968","1969","1970","1971","1972","1973","1974","1975","1976","1977","1978","1979","1980","1981","1982","1983","1984","1985","1986","1987","1988","1989","1990","1991","1992","1993","1994","1995","1996","1997","1998","1999","2000","2001","2002","2003","2004","2005","2006","2007","2008","2009","2010"};

       combo = new JComboBox(comboStrings);
       combo1 = new JComboBox(comboStrings1);
       combo2= new JComboBox(comboStrings2);
     // combo.setEditable(true);
     
             


//PASSWORD

		jPass = new JPasswordField(10);
		jConfirm = new JPasswordField(10);


 //PANELS

		j1 = new JPanel();
		j2 = new JPanel();
		j3 = new JPanel();
		j4 = new JPanel();
		j5 = new JPanel();
		j6 = new JPanel();
		j7 = new JPanel();
		j8 = new JPanel();
		j9 = new JPanel();
		j10 = new JPanel();
		j11 = new JPanel();
		j12 = new JPanel();
                j13= new JPanel();
                

//BUTTON(s)
                jOk= new JButton("OK");
		jSub = new JButton("Submit");
		m = new JRadioButton("Male");
		fem = new JRadioButton("Female");
		bg = new ButtonGroup();
		bg.add(m);
		bg.add(fem);
                jSub.addActionListener(this);

	}

        
        //ADD TO PANEL
	public void launch()
	{

		j1.setLayout(new FlowLayout(FlowLayout.LEFT));
		j1.add(name);
		j1.add(jName);
		j1.add(jLast);

		j2.setLayout(new FlowLayout(FlowLayout.LEFT));
		j2.add(bday);
                j2.add(combo);
                j2.add(combo1);
                j2.add(combo2);


                j3.setLayout(new FlowLayout(FlowLayout.LEFT));
		j3.add(address);
		j3.add(jAdd);

		j4.setLayout(new FlowLayout(FlowLayout.LEFT));
		j4.add(email);
		j4.add(jEmail);

		j5.setLayout(new FlowLayout(FlowLayout.LEFT));
		j5.add(contact);
		j5.add(jContact);

		j6.setLayout(new FlowLayout(FlowLayout.LEFT));
		j6.add(gender);
                j6.add(m);
		j6.add(fem);

		j7.setLayout(new GridLayout(7,1));
		j7.add(title);
		j7.add(j1);
		j7.add(j2);
		j7.add(j3);
		j7.add(j4);
		j7.add(j5);
		j7.add(j6);

		j8.setLayout(new FlowLayout(FlowLayout.LEFT));
		j8.add(user);
		j8.add(jUser);

		j9.setLayout(new FlowLayout(FlowLayout.LEFT));
		j9.add(pass);
		j9.add(jPass);
		j12.add(j11);
                j11.add(jSub);

		j10.setLayout(new FlowLayout(FlowLayout.LEFT));
		j10.add(confirm);
		j10.add(jConfirm);

		j11.setLayout(new FlowLayout());
		

		j12.setLayout(new GridLayout(5,1));
		j12.add(select);
		j12.add(j8);
		j12.add(j9);
		j12.add(j10);
                
             
                
            
		f.setLayout(new GridLayout(2,1));
		f.add(j7);
		f.add(j12);
		f.setVisible(true);
		//f.setSize(320,500);
		f.pack();
		f.setLocation(500,100);
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               
              
	}



        
        
   
        
        
        
 public void launchs(){
  
       

/*j14.add(name);



s=jName.getText();
jName.addActionListener(this);



f2.add(j14);*/
f2.setSize(300, 600);



        




}
        public void actionPerformed(ActionEvent done)
		{

			if(done.getActionCommand().equals("Submit"))
			{
			try{


				String z = jUser.getText();
				File f = new File("D:/Project/" + z + ".txt");
				FileWriter fr = new FileWriter(f);

                               

				String v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11;

				v1 = jUser.getText();
				fr.write(v1+ "\r\n");

				v2 = jPass.getText();
				v3 = jConfirm.getText();

                             jLog Log  = new jLog();

                             //password validation
				if(v2.equals(v3))
				{
				  j13.add(jPass);
                                    fr.write(v2 + "\r\n");

                      

				v4 = jName.getText();
                               
                                fr.write(v4+ "\r\n");

				v5 = jLast.getText();
				fr.write(v5+ "\r\n");

				v6 =(String) combo.getSelectedItem();
				fr.write(v6+ "/");

				v7 = (String) combo1.getSelectedItem();
				fr.write(v7+ "/");

				v8 = (String) combo2.getSelectedItem();
				fr.write(v8+ "\r\n");

				v9 = jAdd.getText();
				fr.write(v9+ "\r\n");
                              
                              
                                
				v10 = jEmail.getText();
				fr.write(v10+ "\r\n");

				v11 = jContact.getText();
				fr.write(v11+ "\r\n");

                              
                            }

                           [B][/B] if(done.getActionCommand().equals("LogIn")[/B][/B]){
                                    
                                    f2.setVisible(true);
                                    


                                }
                          
                                fr.close();
				}

                       
			
                        
                      
                        catch(IOException ioe)
				{
					System.out.print("failed");
				}
			}		}







public class TestRegform
{

	public static void main(String[] args)
	{
		LogIn l = new LogIn();
		l.launch();


	}
}he "LogIn" button.

Recommended Answers

All 6 Replies

can somebody help me to put an action in a button that comes from a different class. Specifically t

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



 class LogIn implements ActionListener
{

    private JFrame f,f2;
    private JButton jLog, jCan, jReg,jOk;
    private JPanel j1, j2, j3, j4,j5,j6;
    private JTextField jText;
    private JPasswordField jPass;
    private JLabel user, pass;

    public LogIn()
    {
        f = new JFrame("Log-In");
                f2= new JFrame("Info");

                jLog = new JButton("Log-In");
        jCan  = new JButton("Cancel");
        jReg = new JButton("Sign-up");
                jOk= new JButton("Ok");

                jLog.addActionListener(this);
        jCan.addActionListener(this);
        jReg.addActionListener(this);
                jOk.addActionListener(this);


        j1 = new JPanel();
        j2 = new JPanel();
        j3 = new JPanel();
        j4 = new JPanel();
                j5= new JPanel();
                j6=new JPanel();



        jText = new JTextField(15);
        jPass = new JPasswordField(15);

        user = new JLabel("Username");
        pass = new JLabel("Password");

    }

    public void launch()
    {
        j1.setLayout(new FlowLayout());
        j1.add(user);
        j1.add(jText);

        j2.setLayout(new FlowLayout());
        j2.add(jLog);
        j2.add(jCan);

        j3.setLayout(new FlowLayout());
        j3.add(pass);
        j3.add(jPass);

        j4.setLayout(new FlowLayout());
        j4.add(jReg);







                f.setLayout(new GridLayout(4,1));
        f.add(j1);
        f.add(j3);
        f.add(j2);
        f.add(j4);
        f.setVisible(true);
        f.pack();
        f.setLocation(250,250);

               //INFO FRAME
                f2.setSize(300,600);

                //f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }




        public void actionPerformed (ActionEvent event)
    {





  //sign up

        if(event.getActionCommand().equals("Sign-up"))
        {
            f.setVisible(false);
            regForm rg = new regForm();
            rg.launch();
        }



//lOGIN button

        else if(event.getActionCommand().equals("Log-In"))
        {

            try{

            String get1 = jText.getText();
            String get2 = jPass.getText();

            FileReader fr = new FileReader("D:/Project/"+  get1 +".txt");

            BufferedReader in = new BufferedReader(fr);
            String str1, str2;

                str1 = in.readLine();
                str2 = in.readLine();


            if((str1.equals(get1)) && (str2.equals(get2)))
            {
                //
                            //System.out.print("Success");

                            /*f.dispose();
                            regForm rg = new regForm();


                            rg.launchs();*/


            }


                        else
            {

            }
                }

            catch(FileNotFoundException e)
            {
                System.out.print("not found"); //
            }
            catch(IOException e)
            {
                System.out.print("not found");
            }

        }


     // CANCEL BUTTON

                 /*if(event.getActionCommand().equals("Cancel")){
                 f.dispose();*/

                }


}


//DECLARATIONS -ACTION LISTENER
class regForm implements ActionListener
{
    private JFrame f,f2;
    private JButton jSub,jOk;
    private JPanel j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12,j13,j14;
    private JPasswordField jPass, jConfirm;

    private JTextField jName, jLast, jUser, jEmail, jContact,
                jMonth, jYear, jDay, jAdd ;

    private JLabel user, pass, confirm, name, email, contact,
             gender, title, bday, address, select;

    private JRadioButton m, fem;
    private ButtonGroup bg;
        private JComboBox combo;

        private JComboBox combo1;
        private JComboBox combo2;

      private String s;

 //FRAME

        public regForm()
    {

        f = new JFrame("Registration Form");
                f2=new JFrame("");
//Labels
        title = new JLabel("PERSONAL INFORMATION", JLabel.CENTER);
        name = new JLabel("Name: ");
        gender = new JLabel("Gender: ");
        bday = new JLabel("Birthday: ");
        email = new JLabel("Email Address: ");
        contact = new JLabel("Contact Number: ");
        user = new JLabel("Username: ");
        pass = new JLabel("Password: ");
        confirm = new JLabel("Confirm Password: ");
        address = new JLabel("Address: ");
        select = new JLabel("CHOOSE YOUR USERNAME AND PASSWORD" , JLabel.CENTER);

        title.setForeground(Color.darkGray);
        title.setFont(new Font("Arial Black", Font.BOLD, 15));
        select.setForeground(Color.black);
        select.setFont(new Font("Calibri", Font.BOLD, 15));
//Text Fields

        jName = new JTextField("First Name",10);
        jLast = new JTextField("Last Name", 10);
        jMonth = new JTextField("MM", 2);
        jDay = new JTextField("DD", 2);
        jYear = new JTextField("YEAR", 4);
        jContact = new JTextField(10);
        jUser = new JTextField(10);
        jEmail =  new JTextField(10);
        jAdd = new JTextField(10);

        jDay.setForeground(Color.gray);
        jMonth.setForeground(Color.gray);
        jYear.setForeground(Color.gray);

 //DROPDOWN BOXES


       String[] comboStrings = { "January", "February", "March", "April", "May","June","July","August","September","October","November","December" };
       String[] comboStrings1= {"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","21","22","23","24","25","26","27","28","29","30","31",};
       String[] comboStrings2={"1960","1962","1963","1964","1965","1966","1967","1968","1969","1970","1971","1972","1973","1974","1975","1976","1977","1978","1979","1980","1981","1982","1983","1984","1985","1986","1987","1988","1989","1990","1991","1992","1993","1994","1995","1996","1997","1998","1999","2000","2001","2002","2003","2004","2005","2006","2007","2008","2009","2010"};

       combo = new JComboBox(comboStrings);
       combo1 = new JComboBox(comboStrings1);
       combo2= new JComboBox(comboStrings2);
     // combo.setEditable(true);




//PASSWORD

        jPass = new JPasswordField(10);
        jConfirm = new JPasswordField(10);


 //PANELS

        j1 = new JPanel();
        j2 = new JPanel();
        j3 = new JPanel();
        j4 = new JPanel();
        j5 = new JPanel();
        j6 = new JPanel();
        j7 = new JPanel();
        j8 = new JPanel();
        j9 = new JPanel();
        j10 = new JPanel();
        j11 = new JPanel();
        j12 = new JPanel();
                j13= new JPanel();


//BUTTON(s)
                jOk= new JButton("OK");
        jSub = new JButton("Submit");
        m = new JRadioButton("Male");
        fem = new JRadioButton("Female");
        bg = new ButtonGroup();
        bg.add(m);
        bg.add(fem);
                jSub.addActionListener(this);

    }


        //ADD TO PANEL
    public void launch()
    {

        j1.setLayout(new FlowLayout(FlowLayout.LEFT));
        j1.add(name);
        j1.add(jName);
        j1.add(jLast);

        j2.setLayout(new FlowLayout(FlowLayout.LEFT));
        j2.add(bday);
                j2.add(combo);
                j2.add(combo1);
                j2.add(combo2);


                j3.setLayout(new FlowLayout(FlowLayout.LEFT));
        j3.add(address);
        j3.add(jAdd);

        j4.setLayout(new FlowLayout(FlowLayout.LEFT));
        j4.add(email);
        j4.add(jEmail);

        j5.setLayout(new FlowLayout(FlowLayout.LEFT));
        j5.add(contact);
        j5.add(jContact);

        j6.setLayout(new FlowLayout(FlowLayout.LEFT));
        j6.add(gender);
                j6.add(m);
        j6.add(fem);

        j7.setLayout(new GridLayout(7,1));
        j7.add(title);
        j7.add(j1);
        j7.add(j2);
        j7.add(j3);
        j7.add(j4);
        j7.add(j5);
        j7.add(j6);

        j8.setLayout(new FlowLayout(FlowLayout.LEFT));
        j8.add(user);
        j8.add(jUser);

        j9.setLayout(new FlowLayout(FlowLayout.LEFT));
        j9.add(pass);
        j9.add(jPass);
        j12.add(j11);
                j11.add(jSub);

        j10.setLayout(new FlowLayout(FlowLayout.LEFT));
        j10.add(confirm);
        j10.add(jConfirm);

        j11.setLayout(new FlowLayout());


        j12.setLayout(new GridLayout(5,1));
        j12.add(select);
        j12.add(j8);
        j12.add(j9);
        j12.add(j10);




        f.setLayout(new GridLayout(2,1));
        f.add(j7);
        f.add(j12);
        f.setVisible(true);
        //f.setSize(320,500);
        f.pack();
        f.setLocation(500,100);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


    }









 public void launchs(){



/*j14.add(name);



s=jName.getText();
jName.addActionListener(this);



f2.add(j14);*/
f2.setSize(300, 600);








}
        public void actionPerformed(ActionEvent done)
        {

            if(done.getActionCommand().equals("Submit"))
            {
            try{


                String z = jUser.getText();
                File f = new File("D:/Project/" + z + ".txt");
                FileWriter fr = new FileWriter(f);



                String v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11;

                v1 = jUser.getText();
                fr.write(v1+ "\r\n");

                v2 = jPass.getText();
                v3 = jConfirm.getText();

                             jLog Log  = new jLog();

                             //password validation
                if(v2.equals(v3))
                {
                  j13.add(jPass);
                                    fr.write(v2 + "\r\n");



                v4 = jName.getText();

                                fr.write(v4+ "\r\n");

                v5 = jLast.getText();
                fr.write(v5+ "\r\n");

                v6 =(String) combo.getSelectedItem();
                fr.write(v6+ "/");

                v7 = (String) combo1.getSelectedItem();
                fr.write(v7+ "/");

                v8 = (String) combo2.getSelectedItem();
                fr.write(v8+ "\r\n");

                v9 = jAdd.getText();
                fr.write(v9+ "\r\n");



                v10 = jEmail.getText();
                fr.write(v10+ "\r\n");

                v11 = jContact.getText();
                fr.write(v11+ "\r\n");


                            }

                           [B][/B] if(done.getActionCommand().equals("LogIn")){

                                    f2.setVisible(true);



                                }

                                fr.close();
                }





                        catch(IOException ioe)
                {
                    System.out.print("failed");
                }
            }       }







public class TestRegform
{

    public static void main(String[] args)
    {
        LogIn l = new LogIn();
        l.launch();


    }
}he "LogIn" button.

Please put your codes inside the CODES tag.


And please ask specific question. What do you want to do exactly??

Im sorry for my first post. What i want to ask is how can i use button from a different class.Specifically my LogIn BUTTON BELOW. i want to put an action for it at the bottom part action event.Thank you.

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



 class LogIn implements ActionListener
{

	private JFrame f,f2;
	private JButton jLog, jCan, jReg,jOk;
	private JPanel j1, j2, j3, j4,j5,j6;
	private JTextField jText;
	private JPasswordField jPass;
	private JLabel user, pass;

	public LogIn()
	{
		f = new JFrame("Log-In");
                f2= new JFrame("Info");

                jLog = new JButton("Log-In");
		jCan  = new JButton("Cancel");
		jReg = new JButton("Sign-up");
                jOk= new JButton("Ok");

                jLog.addActionListener(this);
		jCan.addActionListener(this);
		jReg.addActionListener(this);
                jOk.addActionListener(this);


		j1 = new JPanel();
		j2 = new JPanel();
		j3 = new JPanel();
		j4 = new JPanel();
                j5= new JPanel();
                j6=new JPanel();



		jText = new JTextField(15);
		jPass = new JPasswordField(15);

		user = new JLabel("Username");
		pass = new JLabel("Password");

	}

	public void launch()
	{
		j1.setLayout(new FlowLayout());
		j1.add(user);
		j1.add(jText);

		j2.setLayout(new FlowLayout());
		j2.add(jLog);
		j2.add(jCan);

		j3.setLayout(new FlowLayout());
		j3.add(pass);
		j3.add(jPass);

		j4.setLayout(new FlowLayout());
		j4.add(jReg);

                f.setLayout(new GridLayout(4,1));
		f.add(j1);
		f.add(j3);
		f.add(j2);
		f.add(j4);
		f.setVisible(true);
		f.pack();
		f.setLocation(250,250);

               //INFO FRAME
                f2.setSize(300,600);

                //f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

        public void actionPerformed (ActionEvent event)
	{
  //sign up

		if(event.getActionCommand().equals("Sign-up"))
		{
			f.setVisible(false);
			regForm rg = new regForm();
			rg.launch();
		}



//lOGIN button

		else if(event.getActionCommand().equals("Log-In"))
		{

			try{

			String get1 = jText.getText();
			String get2 = jPass.getText();

			FileReader fr = new FileReader("D:/Project/"+  get1 +".txt");

			BufferedReader in = new BufferedReader(fr);
			String str1, str2;

				str1 = in.readLine();
				str2 = in.readLine();


			if((str1.equals(get1)) && (str2.equals(get2)))
			{
				//
                            //System.out.print("Success");

                            /*f.dispose();
                            regForm rg = new regForm();


                            rg.launchs();*/
                       

			}


                        else
			{
				
			}
				}

			catch(FileNotFoundException e)
			{
				System.out.print("not found"); //
			}
			catch(IOException e)
			{
				System.out.print("not found");
			}
 
		}


     // CANCEL BUTTON
                   
                 /*if(event.getActionCommand().equals("Cancel")){
                 f.dispose();*/

                }
                
                                 
}


//DECLARATIONS -ACTION LISTENER
class regForm implements ActionListener
{
	private JFrame f,f2;
	private JButton jSub,jOk;
	private JPanel j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12,j13,j14;
	private JPasswordField jPass, jConfirm;

	private JTextField jName, jLast, jUser, jEmail, jContact,
				jMonth, jYear, jDay, jAdd ;

	private JLabel user, pass, confirm, name, email, contact,
			 gender, title, bday, address, select;

	private JRadioButton m, fem;
	private ButtonGroup bg;
        private JComboBox combo;

        private JComboBox combo1;
        private JComboBox combo2;
         
      private String s;
         
 //FRAME

        public regForm()
	{

		f = new JFrame("Registration Form");
                f2=new JFrame("");
//Labels
		title = new JLabel("PERSONAL INFORMATION", JLabel.CENTER);
		name = new JLabel("Name: ");
		gender = new JLabel("Gender: ");
		bday = new JLabel("Birthday: ");
		email = new JLabel("Email Address: ");
		contact = new JLabel("Contact Number: ");
		user = new JLabel("Username: ");
		pass = new JLabel("Password: ");
		confirm = new JLabel("Confirm Password: ");
		address = new JLabel("Address: ");
		select = new JLabel("CHOOSE YOUR USERNAME AND PASSWORD" , JLabel.CENTER);

		title.setForeground(Color.darkGray);
		title.setFont(new Font("Arial Black", Font.BOLD, 15));
		select.setForeground(Color.black);
		select.setFont(new Font("Calibri", Font.BOLD, 15));
//Text Fields

		jName = new JTextField("First Name",10);
		jLast = new JTextField("Last Name", 10);
		jMonth = new JTextField("MM", 2);
		jDay = new JTextField("DD", 2);
		jYear = new JTextField("YEAR", 4);
		jContact = new JTextField(10);
		jUser = new JTextField(10);
		jEmail =  new JTextField(10);
		jAdd = new JTextField(10);

		jDay.setForeground(Color.gray);
		jMonth.setForeground(Color.gray);
		jYear.setForeground(Color.gray);

 //DROPDOWN BOXES


       String[] comboStrings = { "January", "February", "March", "April", "May","June","July","August","September","October","November","December" };
       String[] comboStrings1= {"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","21","22","23","24","25","26","27","28","29","30","31",};
       String[] comboStrings2={"1960","1962","1963","1964","1965","1966","1967","1968","1969","1970","1971","1972","1973","1974","1975","1976","1977","1978","1979","1980","1981","1982","1983","1984","1985","1986","1987","1988","1989","1990","1991","1992","1993","1994","1995","1996","1997","1998","1999","2000","2001","2002","2003","2004","2005","2006","2007","2008","2009","2010"};

       combo = new JComboBox(comboStrings);
       combo1 = new JComboBox(comboStrings1);
       combo2= new JComboBox(comboStrings2);
     // combo.setEditable(true);
     
             


//PASSWORD

		jPass = new JPasswordField(10);
		jConfirm = new JPasswordField(10);


 //PANELS

		j1 = new JPanel();
		j2 = new JPanel();
		j3 = new JPanel();
		j4 = new JPanel();
		j5 = new JPanel();
		j6 = new JPanel();
		j7 = new JPanel();
		j8 = new JPanel();
		j9 = new JPanel();
		j10 = new JPanel();
		j11 = new JPanel();
		j12 = new JPanel();
                j13= new JPanel();
                

//BUTTON(s)
                jOk= new JButton("OK");
		jSub = new JButton("Submit");
		m = new JRadioButton("Male");
		fem = new JRadioButton("Female");
		bg = new ButtonGroup();
		bg.add(m);
		bg.add(fem);
                jSub.addActionListener(this);

	}

        
        //ADD TO PANEL
	public void launch()
	{

		j1.setLayout(new FlowLayout(FlowLayout.LEFT));
		j1.add(name);
		j1.add(jName);
		j1.add(jLast);

		j2.setLayout(new FlowLayout(FlowLayout.LEFT));
		j2.add(bday);
                j2.add(combo);
                j2.add(combo1);
                j2.add(combo2);


                j3.setLayout(new FlowLayout(FlowLayout.LEFT));
		j3.add(address);
		j3.add(jAdd);

		j4.setLayout(new FlowLayout(FlowLayout.LEFT));
		j4.add(email);
		j4.add(jEmail);

		j5.setLayout(new FlowLayout(FlowLayout.LEFT));
		j5.add(contact);
		j5.add(jContact);

		j6.setLayout(new FlowLayout(FlowLayout.LEFT));
		j6.add(gender);
                j6.add(m);
		j6.add(fem);

		j7.setLayout(new GridLayout(7,1));
		j7.add(title);
		j7.add(j1);
		j7.add(j2);
		j7.add(j3);
		j7.add(j4);
		j7.add(j5);
		j7.add(j6);

		j8.setLayout(new FlowLayout(FlowLayout.LEFT));
		j8.add(user);
		j8.add(jUser);

		j9.setLayout(new FlowLayout(FlowLayout.LEFT));
		j9.add(pass);
		j9.add(jPass);
		j12.add(j11);
                j11.add(jSub);

		j10.setLayout(new FlowLayout(FlowLayout.LEFT));
		j10.add(confirm);
		j10.add(jConfirm);

		j11.setLayout(new FlowLayout());
		

		j12.setLayout(new GridLayout(5,1));
		j12.add(select);
		j12.add(j8);
		j12.add(j9);
		j12.add(j10);
                
             
                
            
		f.setLayout(new GridLayout(2,1));
		f.add(j7);
		f.add(j12);
		f.setVisible(true);
		//f.setSize(320,500);
		f.pack();
		f.setLocation(500,100);
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               
              
	}



        
        
   
        
        
        
 public void launchs(){
  
       

/*j14.add(name);



s=jName.getText();
jName.addActionListener(this);



f2.add(j14);*/
f2.setSize(300, 600);



        




}
        public void actionPerformed(ActionEvent done)
		{

			if(done.getActionCommand().equals("Submit"))
			{
			try{


				String z = jUser.getText();
				File f = new File("D:/Project/" + z + ".txt");
				FileWriter fr = new FileWriter(f);

                               

				String v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11;

				v1 = jUser.getText();
				fr.write(v1+ "\r\n");

				v2 = jPass.getText();
				v3 = jConfirm.getText();

                             jLog Log  = new jLog();

                             //password validation
				if(v2.equals(v3))
				{
				  j13.add(jPass);
                                    fr.write(v2 + "\r\n");

                      

				v4 = jName.getText();
                               
                                fr.write(v4+ "\r\n");

				v5 = jLast.getText();
				fr.write(v5+ "\r\n");

				v6 =(String) combo.getSelectedItem();
				fr.write(v6+ "/");

				v7 = (String) combo1.getSelectedItem();
				fr.write(v7+ "/");

				v8 = (String) combo2.getSelectedItem();
				fr.write(v8+ "\r\n");

				v9 = jAdd.getText();
				fr.write(v9+ "\r\n");
                              
                              
                                
				v10 = jEmail.getText();
				fr.write(v10+ "\r\n");

				v11 = jContact.getText();
				fr.write(v11+ "\r\n");

                              
                            }

                                if(done.getActionCommand().equals("LogIn")){
                                    
                                    f2.setVisible(true);
                                    


                                }
                          
                                fr.close();
				}

                       
			
                        
                      
                        catch(IOException ioe)
				{
					System.out.print("failed");
				}
			}		}



}


public class TestRegform
{

	public static void main(String[] args)
	{
		LogIn l = new LogIn();
		l.launch();


	}
}

Please put your codes inside the CODES tag.


And please ask specific question. What do you want to do exactly??

im sorry. i posted it again.

Can you help me to perform an action event for a button that came from a different class.Specifically the LogIn button of my codes below. I want to use it at the last actionEvent at the bottom part.
pleaaaaasse.:))

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



 class LogIn implements ActionListener
{

	private JFrame f,f2;
	private JButton jLog, jCan, jReg,jOk;
	private JPanel j1, j2, j3, j4,j5,j6;
	private JTextField jText;
	private JPasswordField jPass;
	private JLabel user, pass;

	public LogIn()
	{
		f = new JFrame("Log-In");
                f2= new JFrame("Info");

                jLog = new JButton("Log-In");
		jCan  = new JButton("Cancel");
		jReg = new JButton("Sign-up");
                jOk= new JButton("Ok");

                jLog.addActionListener(this);
		jCan.addActionListener(this);
		jReg.addActionListener(this);
                jOk.addActionListener(this);


		j1 = new JPanel();
		j2 = new JPanel();
		j3 = new JPanel();
		j4 = new JPanel();
                j5= new JPanel();
                j6=new JPanel();



		jText = new JTextField(15);
		jPass = new JPasswordField(15);

		user = new JLabel("Username");
		pass = new JLabel("Password");

	}

	public void launch()
	{
		j1.setLayout(new FlowLayout());
		j1.add(user);
		j1.add(jText);

		j2.setLayout(new FlowLayout());
		j2.add(jLog);
		j2.add(jCan);

		j3.setLayout(new FlowLayout());
		j3.add(pass);
		j3.add(jPass);

		j4.setLayout(new FlowLayout());
		j4.add(jReg);

                f.setLayout(new GridLayout(4,1));
		f.add(j1);
		f.add(j3);
		f.add(j2);
		f.add(j4);
		f.setVisible(true);
		f.pack();
		f.setLocation(250,250);

               //INFO FRAME
                f2.setSize(300,600);

                //f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

        public void actionPerformed (ActionEvent event)
	{
  //sign up

		if(event.getActionCommand().equals("Sign-up"))
		{
			f.setVisible(false);
			regForm rg = new regForm();
			rg.launch();
		}



//lOGIN button

		else if(event.getActionCommand().equals("Log-In"))
		{

			try{

			String get1 = jText.getText();
			String get2 = jPass.getText();

			FileReader fr = new FileReader("D:/Project/"+  get1 +".txt");

			BufferedReader in = new BufferedReader(fr);
			String str1, str2;

				str1 = in.readLine();
				str2 = in.readLine();


			if((str1.equals(get1)) && (str2.equals(get2)))
			{
				//
                            //System.out.print("Success");

                            /*f.dispose();
                            regForm rg = new regForm();


                            rg.launchs();*/
                       

			}


                        else
			{
				
			}
				}

			catch(FileNotFoundException e)
			{
				System.out.print("not found"); //
			}
			catch(IOException e)
			{
				System.out.print("not found");
			}
 
		}


     // CANCEL BUTTON
                   
                 /*if(event.getActionCommand().equals("Cancel")){
                 f.dispose();*/

                }
                
                                 
}


//DECLARATIONS -ACTION LISTENER
class regForm implements ActionListener
{
	private JFrame f,f2;
	private JButton jSub,jOk;
	private JPanel j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12,j13,j14;
	private JPasswordField jPass, jConfirm;

	private JTextField jName, jLast, jUser, jEmail, jContact,
				jMonth, jYear, jDay, jAdd ;

	private JLabel user, pass, confirm, name, email, contact,
			 gender, title, bday, address, select;

	private JRadioButton m, fem;
	private ButtonGroup bg;
        private JComboBox combo;

        private JComboBox combo1;
        private JComboBox combo2;
         
      private String s;
         
 //FRAME

        public regForm()
	{

		f = new JFrame("Registration Form");
                f2=new JFrame("");
//Labels
		title = new JLabel("PERSONAL INFORMATION", JLabel.CENTER);
		name = new JLabel("Name: ");
		gender = new JLabel("Gender: ");
		bday = new JLabel("Birthday: ");
		email = new JLabel("Email Address: ");
		contact = new JLabel("Contact Number: ");
		user = new JLabel("Username: ");
		pass = new JLabel("Password: ");
		confirm = new JLabel("Confirm Password: ");
		address = new JLabel("Address: ");
		select = new JLabel("CHOOSE YOUR USERNAME AND PASSWORD" , JLabel.CENTER);

		title.setForeground(Color.darkGray);
		title.setFont(new Font("Arial Black", Font.BOLD, 15));
		select.setForeground(Color.black);
		select.setFont(new Font("Calibri", Font.BOLD, 15));
//Text Fields

		jName = new JTextField("First Name",10);
		jLast = new JTextField("Last Name", 10);
		jMonth = new JTextField("MM", 2);
		jDay = new JTextField("DD", 2);
		jYear = new JTextField("YEAR", 4);
		jContact = new JTextField(10);
		jUser = new JTextField(10);
		jEmail =  new JTextField(10);
		jAdd = new JTextField(10);

		jDay.setForeground(Color.gray);
		jMonth.setForeground(Color.gray);
		jYear.setForeground(Color.gray);

 //DROPDOWN BOXES


       String[] comboStrings = { "January", "February", "March", "April", "May","June","July","August","September","October","November","December" };
       String[] comboStrings1= {"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","21","22","23","24","25","26","27","28","29","30","31",};
       String[] comboStrings2={"1960","1962","1963","1964","1965","1966","1967","1968","1969","1970","1971","1972","1973","1974","1975","1976","1977","1978","1979","1980","1981","1982","1983","1984","1985","1986","1987","1988","1989","1990","1991","1992","1993","1994","1995","1996","1997","1998","1999","2000","2001","2002","2003","2004","2005","2006","2007","2008","2009","2010"};

       combo = new JComboBox(comboStrings);
       combo1 = new JComboBox(comboStrings1);
       combo2= new JComboBox(comboStrings2);
     // combo.setEditable(true);
     
             


//PASSWORD

		jPass = new JPasswordField(10);
		jConfirm = new JPasswordField(10);


 //PANELS

		j1 = new JPanel();
		j2 = new JPanel();
		j3 = new JPanel();
		j4 = new JPanel();
		j5 = new JPanel();
		j6 = new JPanel();
		j7 = new JPanel();
		j8 = new JPanel();
		j9 = new JPanel();
		j10 = new JPanel();
		j11 = new JPanel();
		j12 = new JPanel();
                j13= new JPanel();
                

//BUTTON(s)
                jOk= new JButton("OK");
		jSub = new JButton("Submit");
		m = new JRadioButton("Male");
		fem = new JRadioButton("Female");
		bg = new ButtonGroup();
		bg.add(m);
		bg.add(fem);
                jSub.addActionListener(this);

	}

        
        //ADD TO PANEL
	public void launch()
	{

		j1.setLayout(new FlowLayout(FlowLayout.LEFT));
		j1.add(name);
		j1.add(jName);
		j1.add(jLast);

		j2.setLayout(new FlowLayout(FlowLayout.LEFT));
		j2.add(bday);
                j2.add(combo);
                j2.add(combo1);
                j2.add(combo2);


                j3.setLayout(new FlowLayout(FlowLayout.LEFT));
		j3.add(address);
		j3.add(jAdd);

		j4.setLayout(new FlowLayout(FlowLayout.LEFT));
		j4.add(email);
		j4.add(jEmail);

		j5.setLayout(new FlowLayout(FlowLayout.LEFT));
		j5.add(contact);
		j5.add(jContact);

		j6.setLayout(new FlowLayout(FlowLayout.LEFT));
		j6.add(gender);
                j6.add(m);
		j6.add(fem);

		j7.setLayout(new GridLayout(7,1));
		j7.add(title);
		j7.add(j1);
		j7.add(j2);
		j7.add(j3);
		j7.add(j4);
		j7.add(j5);
		j7.add(j6);

		j8.setLayout(new FlowLayout(FlowLayout.LEFT));
		j8.add(user);
		j8.add(jUser);

		j9.setLayout(new FlowLayout(FlowLayout.LEFT));
		j9.add(pass);
		j9.add(jPass);
		j12.add(j11);
                j11.add(jSub);

		j10.setLayout(new FlowLayout(FlowLayout.LEFT));
		j10.add(confirm);
		j10.add(jConfirm);

		j11.setLayout(new FlowLayout());
		

		j12.setLayout(new GridLayout(5,1));
		j12.add(select);
		j12.add(j8);
		j12.add(j9);
		j12.add(j10);
                
             
                
            
		f.setLayout(new GridLayout(2,1));
		f.add(j7);
		f.add(j12);
		f.setVisible(true);
		//f.setSize(320,500);
		f.pack();
		f.setLocation(500,100);
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               
              
	}



        
        
   
        
        
        
 public void launchs(){
  
       

/*j14.add(name);



s=jName.getText();
jName.addActionListener(this);



f2.add(j14);*/
f2.setSize(300, 600);

}
        public void actionPerformed(ActionEvent done)
		{

			if(done.getActionCommand().equals("Submit"))
			{
			try{


				String z = jUser.getText();
				File f = new File("D:/Project/" + z + ".txt");
				FileWriter fr = new FileWriter(f);

				String v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11;

				v1 = jUser.getText();
				fr.write(v1+ "\r\n");

				v2 = jPass.getText();
				v3 = jConfirm.getText();

                             jLog Log  = new jLog();

                             //password validation
				if(v2.equals(v3))
				{
				  j13.add(jPass);
                                    fr.write(v2 + "\r\n");

                      

				v4 = jName.getText();
                               
                                fr.write(v4+ "\r\n");

				v5 = jLast.getText();
				fr.write(v5+ "\r\n");

				v6 =(String) combo.getSelectedItem();
				fr.write(v6+ "/");

				v7 = (String) combo1.getSelectedItem();
				fr.write(v7+ "/");

				v8 = (String) combo2.getSelectedItem();
				fr.write(v8+ "\r\n");

				v9 = jAdd.getText();
				fr.write(v9+ "\r\n");
                              
                              
                                
				v10 = jEmail.getText();
				fr.write(v10+ "\r\n");

				v11 = jContact.getText();
				fr.write(v11+ "\r\n");

                              
                            }

                                if(done.getActionCommand().equals("LogIn")){
                                    
                                    f2.setVisible(true);
                                    


                                }
                          
                                fr.close();
				}

                       
			
                        
                      
                        catch(IOException ioe)
				{
					System.out.print("failed");
				}
			}		}



}


public class TestRegform
{

	public static void main(String[] args)
	{
		LogIn l = new LogIn();
		l.launch();


	}
}

Instead of using "this" use an instance of the other class.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.