Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package loginSys;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JOptionPane;
- import javax.swing.JTextField;
- import javax.swing.JButton;
- import javax.swing.JLabel;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import javax.swing.JPasswordField;
- import javax.swing.JSeparator;
- import java.awt.Toolkit;
- import java.awt.Window.Type;
- public class Login {
- private JFrame frame;
- private JTextField txtUsername;
- private JPasswordField txtPassword;
- /**
- * Main Application
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Login window = new Login();
- window.frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the application.
- */
- public Login() {
- initialize();
- }
- /**
- * Contents of the frame
- */
- private void initialize() {
- frame = new JFrame();
- frame.setIconImage(Toolkit.getDefaultToolkit().getImage("C:\\Users\\Rabbi\\Pictures\\Untitled.png"));
- frame.setBounds(100, 100, 450, 300);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.getContentPane().setLayout(null);
- txtUsername = new JTextField();
- txtUsername.setBounds(172, 90, 123, 20);
- frame.getContentPane().add(txtUsername);
- txtUsername.setColumns(10);
- JButton btnLogin = new JButton("Login");
- btnLogin.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- String password = txtPassword.getText();
- String username = txtUsername.getText();
- if(password.contains("Hello")&&username.contains("Rabbi")){
- txtUsername.setText(null);
- txtPassword.setText(null);
- }
- else
- {
- JOptionPane.showMessageDialog(null,"Invalid Username Or Password", null,JOptionPane.ERROR_MESSAGE);
- }
- }
- });
- btnLogin.setBounds(45, 203, 89, 23);
- frame.getContentPane().add(btnLogin);
- JButton btnNewButton_1 = new JButton("Exit");
- btnNewButton_1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- System.exit(0);
- }
- });
- btnNewButton_1.setBounds(305, 203, 89, 23);
- frame.getContentPane().add(btnNewButton_1);
- JLabel lblLoginSystem = new JLabel("Login System");
- lblLoginSystem.setBounds(187, 11, 95, 43);
- frame.getContentPane().add(lblLoginSystem);
- JLabel lblUserName = new JLabel("UserName");
- lblUserName.setBounds(85, 93, 65, 14);
- frame.getContentPane().add(lblUserName);
- JLabel lblPassword = new JLabel("Password");
- lblPassword.setBounds(85, 134, 68, 14);
- frame.getContentPane().add(lblPassword);
- txtPassword = new JPasswordField();
- txtPassword.setBounds(172, 131, 123, 20);
- frame.getContentPane().add(txtPassword);
- JSeparator separator = new JSeparator();
- separator.setBounds(131, 52, 186, 2);
- frame.getContentPane().add(separator);
- JButton btnReset = new JButton("Reset");
- btnReset.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- txtUsername.setText(null);
- txtPassword.setText(null);
- }
- });
- btnReset.setBounds(172, 203, 89, 23);
- frame.getContentPane().add(btnReset);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement