I have a JFrame which uses JPanel initialized from the JPanel.
This is the JFrame class : LoginPage
public class LoginPage extends JFrame
{
private JPanel contentPane;
static int cnf;
static String data;
private static LoginPage frame;
/**
* Launch the application.
*/
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
try
{
frame = new LoginPage();
frame.setVisible(true);
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
//cnf = chk;
if( cnf == 1)
{
frame.dispose();
JFrame m = new MainPage();
m.setVisible(true);
}
}
/**
* Create the frame.
*/
public LoginPage()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel m = new MainLogin();
m.setBounds(0, 0, 448, 271);
contentPane.add(m);
}
}
And, this is the JPanel class : MainLogin
public class MainLogin extends JPanel
{
private JTextField uname;
private JPasswordField pass;
public static int chk;
public MainLogin()
{
setLayout(null);
uname = new JTextField();
uname.setBounds(236, 22, 167, 25);
add(uname);
uname.setColumns(10);
pass = new JPasswordField();
pass.setBounds(236, 53, 167, 25);
add(pass);
JButton login = new JButton("Login");
login.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String u = uname.getText();
char[] tp = pass.getPassword();
String p = new String(tp);
chk = authentication.verify(u, p);
System.out.println(chk);
}
});
login.setBounds(235, 90, 117, 25);
add(login);
}
}
As in the MainLogin
Panel, there is a class authentication
who has a method verify()
, which returns an integer, and this integer is stored in chk
.
Since, this chk
resides in MainLogin
JPanel class, I want to pass it to the LoginPage
JFrame class.
Is there any way to do this other than using a File?