Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. actionPerformed in another class

actionPerformed in another class

Scheduled Pinned Locked Moved Java
questionjavadatabasedocker
3 Posts 3 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chdboy
    wrote on last edited by
    #1

    How can I use another class actionPerformed in another main class? I want to use this class actionperformed

    import java.sql.DriverManager;
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;

    import java.awt.Container;
    import javax.swing.JOptionPane;
    import java.awt.Frame;
    import java.awt.event.*;
    import java.io.IOException;

    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JPasswordField;
    import javax.swing.JTextField;
    import javax.swing.SpringLayout;

    public class SpringSample extends Frame implements ActionListener

    {
    JLabel F_namelbl = new JLabel("Username: ");
    JLabel L_namelbl = new JLabel("Password: ");
    JTextField tf_Fname = new JTextField(15);
    JPasswordField tf_Lname = new JPasswordField(15);
    JLabel Lbl_HW = new JLabel("< Login Area >");
    JButton Btn = new JButton("Login");
    JButton btn_cancel = new JButton("Cancel");

    /\*\*
     \* 
     \*/
    private static final long serialVersionUID = 1L;
    
    SpringSample()
    {
    	
        
    	 JFrame frame = new JFrame("Login Area!");		 
    	    frame.setDefaultCloseOperation(JFrame.EXIT\_ON\_CLOSE);
    	    Container contentPane = frame.getContentPane();
    	    JPanel p = new JPanel(new SpringLayout());
    	    SpringLayout layout = (new SpringLayout());
    	    contentPane.setLayout(layout);		   
    	    JPanel p1=new JPanel();    
    	   
    	     
    	    //--------------------------------------------------------------------------------------------------------------------
    	    
    	    //---------------------------------------------------------------------------------------------------------------------
    	    /\*Adding Components to the ContentPane \*/
    	    frame.add(p1);
    	    contentPane.add(F\_namelbl);
    	    contentPane.add(L\_namelbl);
    	    contentPane.add(tf\_Fname);
    	    contentPane.add(tf\_Lname);
    	    contentPane.add(Lbl\_HW);
    	    contentPane.add(Btn);
    	    contentPane.add(btn\_cancel);
    	    	    
    	      //--------------------------------------------------------------------------------------------------------------------
    	    /\*Lay out Components according to the position and coordinates on the SpringLayout\*/
    	    
    	    layout.putConstraint(SpringLayout.WEST, Lbl\_HW, 140, SpringLayout.WEST, contentPane);
    	    layout.putConstraint(SpringLayout.NORTH, Lbl\_HW, 0, SpringLayout.NORTH, contentPane);    
    	    layout.putConstraint(SpringLay
    
    L S 2 Replies Last reply
    0
    • C chdboy

      How can I use another class actionPerformed in another main class? I want to use this class actionperformed

      import java.sql.DriverManager;
      import java.sql.Connection;
      import java.sql.ResultSet;
      import java.sql.SQLException;
      import java.sql.Statement;

      import java.awt.Container;
      import javax.swing.JOptionPane;
      import java.awt.Frame;
      import java.awt.event.*;
      import java.io.IOException;

      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.JPanel;
      import javax.swing.JPasswordField;
      import javax.swing.JTextField;
      import javax.swing.SpringLayout;

      public class SpringSample extends Frame implements ActionListener

      {
      JLabel F_namelbl = new JLabel("Username: ");
      JLabel L_namelbl = new JLabel("Password: ");
      JTextField tf_Fname = new JTextField(15);
      JPasswordField tf_Lname = new JPasswordField(15);
      JLabel Lbl_HW = new JLabel("< Login Area >");
      JButton Btn = new JButton("Login");
      JButton btn_cancel = new JButton("Cancel");

      /\*\*
       \* 
       \*/
      private static final long serialVersionUID = 1L;
      
      SpringSample()
      {
      	
          
      	 JFrame frame = new JFrame("Login Area!");		 
      	    frame.setDefaultCloseOperation(JFrame.EXIT\_ON\_CLOSE);
      	    Container contentPane = frame.getContentPane();
      	    JPanel p = new JPanel(new SpringLayout());
      	    SpringLayout layout = (new SpringLayout());
      	    contentPane.setLayout(layout);		   
      	    JPanel p1=new JPanel();    
      	   
      	     
      	    //--------------------------------------------------------------------------------------------------------------------
      	    
      	    //---------------------------------------------------------------------------------------------------------------------
      	    /\*Adding Components to the ContentPane \*/
      	    frame.add(p1);
      	    contentPane.add(F\_namelbl);
      	    contentPane.add(L\_namelbl);
      	    contentPane.add(tf\_Fname);
      	    contentPane.add(tf\_Lname);
      	    contentPane.add(Lbl\_HW);
      	    contentPane.add(Btn);
      	    contentPane.add(btn\_cancel);
      	    	    
      	      //--------------------------------------------------------------------------------------------------------------------
      	    /\*Lay out Components according to the position and coordinates on the SpringLayout\*/
      	    
      	    layout.putConstraint(SpringLayout.WEST, Lbl\_HW, 140, SpringLayout.WEST, contentPane);
      	    layout.putConstraint(SpringLayout.NORTH, Lbl\_HW, 0, SpringLayout.NORTH, contentPane);    
      	    layout.putConstraint(SpringLay
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Rather than dumping a lot of code, try explaining your problem in clear terms. If you need to call a method of a class then create an object of that class and call the method as normal. however, if that is not your question then please clarify.

      Use the best guess

      1 Reply Last reply
      0
      • C chdboy

        How can I use another class actionPerformed in another main class? I want to use this class actionperformed

        import java.sql.DriverManager;
        import java.sql.Connection;
        import java.sql.ResultSet;
        import java.sql.SQLException;
        import java.sql.Statement;

        import java.awt.Container;
        import javax.swing.JOptionPane;
        import java.awt.Frame;
        import java.awt.event.*;
        import java.io.IOException;

        import javax.swing.JButton;
        import javax.swing.JFrame;
        import javax.swing.JLabel;
        import javax.swing.JPanel;
        import javax.swing.JPasswordField;
        import javax.swing.JTextField;
        import javax.swing.SpringLayout;

        public class SpringSample extends Frame implements ActionListener

        {
        JLabel F_namelbl = new JLabel("Username: ");
        JLabel L_namelbl = new JLabel("Password: ");
        JTextField tf_Fname = new JTextField(15);
        JPasswordField tf_Lname = new JPasswordField(15);
        JLabel Lbl_HW = new JLabel("< Login Area >");
        JButton Btn = new JButton("Login");
        JButton btn_cancel = new JButton("Cancel");

        /\*\*
         \* 
         \*/
        private static final long serialVersionUID = 1L;
        
        SpringSample()
        {
        	
            
        	 JFrame frame = new JFrame("Login Area!");		 
        	    frame.setDefaultCloseOperation(JFrame.EXIT\_ON\_CLOSE);
        	    Container contentPane = frame.getContentPane();
        	    JPanel p = new JPanel(new SpringLayout());
        	    SpringLayout layout = (new SpringLayout());
        	    contentPane.setLayout(layout);		   
        	    JPanel p1=new JPanel();    
        	   
        	     
        	    //--------------------------------------------------------------------------------------------------------------------
        	    
        	    //---------------------------------------------------------------------------------------------------------------------
        	    /\*Adding Components to the ContentPane \*/
        	    frame.add(p1);
        	    contentPane.add(F\_namelbl);
        	    contentPane.add(L\_namelbl);
        	    contentPane.add(tf\_Fname);
        	    contentPane.add(tf\_Lname);
        	    contentPane.add(Lbl\_HW);
        	    contentPane.add(Btn);
        	    contentPane.add(btn\_cancel);
        	    	    
        	      //--------------------------------------------------------------------------------------------------------------------
        	    /\*Lay out Components according to the position and coordinates on the SpringLayout\*/
        	    
        	    layout.putConstraint(SpringLayout.WEST, Lbl\_HW, 140, SpringLayout.WEST, contentPane);
        	    layout.putConstraint(SpringLayout.NORTH, Lbl\_HW, 0, SpringLayout.NORTH, contentPane);    
        	    layout.putConstraint(SpringLay
        
        S Offline
        S Offline
        Shubhashish_Mandal
        wrote on last edited by
        #3

        You can only register an event handler to an event source. So your first class is an event handler. And there fore you can use this to any of the event source which trigger that event. Something like this.

        class Handler implements ActionPerformed{

        public void actionPerformed(ActionEvent e) {}
        }
        }
        class Source {
        p s v main(){
        JButton bt = new Jbutton("Ok");
        bt.addActionListener(new Handler());
        }
        }

        Regards Shubhashish

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups