pbl, so confused, tried everything. I have my Login class where i create my GUI, and i am trying to move the methods to their own class.
CODE
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.awt.*;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.*;
public class Login extends JDialog implements ActionListener
{
ArrayList personsList;
PersonDAO pDAO;
JLabel userName, passWord;
JTextField userName1;
JPasswordField passWord1;
JButton jbnClear, jbnSubmit, jbnCancel;
String userName2, passWord2;
Container cPane;
public Login(JFrame father) {
super(father);
createGUI();
userName2 = "";
passWord2 = "";
personsList = new ArrayList();
pDAO = new PersonDAO();
}
public void createGUI(){
cPane = getContentPane();
setLayout(new GridBagLayout());
//Arrange components on contentPane and set Action Listeners to each JButton
arrangeComponents();
setSize(210,170);
setTitle("Login");
setResizable(false);
setVisible(true);
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
}
public void arrangeComponents(){
userName = new JLabel("Username");
passWord = new JLabel("Password");
userName1 = new JTextField(20);
passWord1 = new JPasswordField(20);
jbnClear = new JButton("Clear");
jbnSubmit = new JButton("Submit");
jbnCancel = new JButton("Cancel");
jbnClear.addActionListener(this);
jbnSubmit.addActionListener(this);
jbnCancel.addActionListener(this);
}
public void actionPerformed (ActionEvent e){
if (e.getSource() == jbnClear){
clear();
}
else if (e.getSource() == jbnSubmit){
//Submit();
}
else if (e.getSource() == jbnCancel){
cancel();
}
}
String getUsername() {
return userName1.getText();
}
String getPassword() {
return new String(passWord1.getPassword());
}
public void clear(){
userName1.setText("");
passWord1.setText("");
personsList.clear();
}
public void cancel(){
this.dispose();
}
}
I removed all the layout to shorten the code. Now i am creating a new class with the methods associated with this class.
CODE
import java.util.ArrayList;
import javax.swing.JOptionPane;
import java.awt.*;
import javax.swing.*;
public class LogRegMethods
{
ArrayList personsList;
PersonDAO pDAO;
Login log;
String userName2, passWord2;
public LogRegMethods()
{
userName2 = "";
passWord2 = "";
personsList = new ArrayList();
pDAO = new PersonDAO();
log = new Login();
}
public void Submit(){
userName2 = log.getUsername();
passWord2 = log.getPassword();
PersonInfo person = new PersonInfo(userName2, passWord2);
if(userName2.equals("") || passWord2.equals("")){
JOptionPane.showMessageDialog(null, "Please complete all fields.");
}
else
{
pDAO.loginPerson(person);
}
}
}
My problem relates to this
CODE
log = new Login();
because in my Login class, its set like
CODE
public Login(JFrame father)
I have no idea what frame to pass it in my method class or how to do it.
cheers