actionPerformed in another class
-
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
-
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
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
-
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
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