Login Panel


import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.border.BevelBorder;
import java.awt.Color;
import javax.swing.border.EtchedBorder;
import javax.swing.border.LineBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.Toolkit;
import javax.swing.ImageIcon;
import java.awt.SystemColor;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class StdLogin extends JDialog {

private final JPanel contentPanel = new JPanel();
private JTextField tfUserName;
private JPasswordField passwordField;
private String uName="23526";
private String pWord="java";


public StdLogin()
{
setResizable(false);
setIconImage(Toolkit.getDefaultToolkit().getImage("C:\\Users\\Ali\\Desktop\\pic for project\\HU_logo_jpeg_400x400.png"));
setTitle("Studnet Login");
setBounds(100, 100, 442, 280);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
contentPanel.setLayout(null);
JPanel panel = new JPanel();
panel.setBorder(new LineBorder(Color.LIGHT_GRAY, 2, true));
panel.setBounds(195, 25, 206, 143);
contentPanel.add(panel);
panel.setLayout(null);
{
JLabel lblUserName = new JLabel("Roll No.");
lblUserName.setBounds(24, 26, 149, 14);
panel.add(lblUserName);
}
{
tfUserName = new JTextField();
tfUserName.setBounds(24, 46, 149, 20);
panel.add(tfUserName);
tfUserName.setColumns(10);
}
{
JLabel lblPw = new JLabel("Password");
lblPw.setBounds(24, 87, 149, 14);
panel.add(lblPw);
}
{
passwordField = new JPasswordField();
passwordField.setBounds(24, 110, 149, 20);
panel.add(passwordField);
}
JPanel panel_1 = new JPanel();
panel_1.setBackground(SystemColor.window);
panel_1.setBorder(new LineBorder(Color.LIGHT_GRAY, 2));
panel_1.setBounds(0, 11, 434, 165);
contentPanel.add(panel_1);
panel_1.setLayout(null);
{
JLabel lblUniLogo = new JLabel("");
lblUniLogo.setIcon(new ImageIcon("C:\\Users\\Ali\\Desktop\\pic for project\\12107964_10153161750172688_8872249596591658378_n.jpg"));
lblUniLogo.setBounds(41, 25, 100, 116);
panel_1.add(lblUniLogo);
}
{
JButton btnLogin = new JButton("");
btnLogin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// condition for check correct user name and password
if (tfUserName.getText().equalsIgnoreCase(uName) && passwordField.getText().equalsIgnoreCase(pWord))
{
MainInter m = new MainInter();
m.setVisible(true);
dispose();
}
else
JOptionPane.showMessageDialog(null, "Please enter a valid Id and Password");
}
});
btnLogin.setIcon(new ImageIcon("C:\\Users\\Ali\\Desktop\\pic for project\\btn login.PNG"));
btnLogin.setBounds(148, 187, 147, 47);
contentPanel.add(btnLogin);
}
}
}

Comments

Popular posts from this blog

Umbrella activities in Software Engineering

Operating System | Best Definition of Opetating System