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();
	} //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[])
	  Login frame=new Login();
	  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.setLayout(new GridLayout(4,0,10,10)); 
			JButton addStaff = new JButton("Add Staff");
			addStaff.addActionListener(new AddStaffListener());
			ManageGUI.add(new JButton("Change Price"));
			JButton editStaff = new JButton("Edit Staff Details");
			editStaff.addActionListener(new EditStaffListener());
			JButton removeStaff = new JButton("Remove Staff Account");
			removeStaff.addActionListener(new removeStaffListener());
			} else {
				JOptionPane.showMessageDialog(null,"Incorrect login or password",
Login required = new Login();
int pass = Login.accessGrant;

Here you create a Login() then immediately query the value of its accessGrant variable. That query happens before Swing gets to display the dialog, and certainly long before the user could enter anything.

If you want your code to wait for user response, try using a modal dialog instead of a JFrame for the Login class.

This article has been dead for over six months. Start a new discussion instead.