Question

Ok. So I'm trying to make a Login tab. It won't run. All it says "Process Completed." Somebody? :)


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;

public class Login extends JFrame implements ActionListener
{

    JLabel User = new JLabel ("Username: ");
    JTextField txtUser = new JTextField(20);
    JLabel UserPass = new JLabel ("Password: ");
    JPasswordField txtPass = new JPasswordField(20);
    JLabel RemarksLabel = new JLabel();
    JButton OK = new JButton ("OK");
    JButton Cancel = new JButton ("Cancel");

    Container c = getContentPane();

    public Login()
    {
        c.setLayout (null);
        c.setBackground(Color.GRAY);
        c.add(User);
        User.setForeground(Color.WHITE);
        c.add(txtUser);
        c.add(UserPass);
        UserPass.setForeground(Color.WHITE);
        c.add(txtPass);
        c.add(RemarksLabel);
        c.add(OK);
        c.add(Cancel);

        User.setBounds(10,20,80,20);
        txtUser.setBounds(80,20,100,20);
        UserPass.setBounds(10,45,80,20);
        txtPass.setBounds(80,45,100,20);
        OK.setBounds(70,70,55,20);
        Cancel.setBounds(125,70,55,20);
        txtPass.addActionListener(this);
        OK.addActionListener(this);
        Cancel.addActionListener(this);
    }

    public void actionPerformed(ActionEvent e)
    {
        String userInput = txtUser.getText();
        String passInput = txtPass.getText();

        if (userInput.equals("Admin") && passInput.equals("admin"))
        {
            setVisible(true);
            JOptionPane.showMessageDialog(null, "sdf");
        }
        else
        {
            RemarksLabel.setForeground(Color.red);
            RemarksLabel.setFont(new Font("Tahoma", Font.BOLD, 12));
            RemarksLabel.setText("Invalid Username/Password");
        }
    }

    public static void main (String args[])
    {
        new Login();
    }
}
Was it helpful?

Solution

You have to show your window:

public static void main (String args[])
{
    JFrame l = new Login();
    l.setVisible(true);
    // Or l.show();
}

Look at http://docs.oracle.com/javase/7/docs/api/java/awt/Window.html#setVisible%28boolean%29

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top