import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Login extends JFrame{
JButton SUBMIT;
JPanel panel;
JLabel label1, label2;
public static int accessGrant = 1;
JTextField username;
JPasswordField pw;
public Login() {
label1 = new JLabel();
label1.setText("Username: ");
username = new JTextField(15);
label2 = new JLabel();
label2.setText("Password: ");
pw = new JPasswordField(15);
SUBMIT = new JButton("SUBMIT");
SUBMIT.addActionListener(new Loginlistener());
panel = new JPanel();
panel.add(label1);
panel.add(username);
panel.add(label2);
panel.add(pw);
panel.add(SUBMIT);
} //end login method
public class Loginlistener implements ActionListener {
public void actionPerformed(ActionEvent e) {
String value1 = username.getText();
String value2 = pw.getText();
if (value1.equals("admin") && value2.equals("12345")) {
accessGrant = 1;
}
else {
accessGrant = 0;
// JOptionPane.showMessageDialog(this,"Incorrect login or password, please try again",
// "Error",JOptionPane.ERROR_MESSAGE);
}
} }
public static void main(String arg[])
{
try
{
Login frame=new Login();
frame.setSize(300,100);
frame.setVisible(true);
}
catch(Exception e)
{JOptionPane.showMessageDialog(null, e.getMessage());}
}
}
How do i get this frame to go up on Main_GUI class. it doesnt pop up and only displays the incorrect password statement.
heres main_GUI
public class ManagementListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
Login required = new Login();
int pass = Login.accessGrant; //[B]THIS BIT IS THE PROBLEM[/B]
if (pass == 1) {
JFrame ManageGUI = new JFrame("Car Park Management");// Newwww Frame
ManageGUI.setVisible(true);
ManageGUI.setSize(400,400);
ManageGUI.setLayout(new GridLayout(4,0,10,10));
JButton addStaff = new JButton("Add Staff");
ManageGUI.add(addStaff);
addStaff.addActionListener(new AddStaffListener());
ManageGUI.add(new JButton("Change Price"));
JButton editStaff = new JButton("Edit Staff Details");
ManageGUI.add(editStaff);
editStaff.addActionListener(new EditStaffListener());
JButton removeStaff = new JButton("Remove Staff Account");
ManageGUI.add(removeStaff);
removeStaff.addActionListener(new removeStaffListener());
} else {
JOptionPane.showMessageDialog(null,"Incorrect login or password",
"Error",JOptionPane.ERROR_MESSAGE);
}
}
}