Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JPasswordField;
- import javax.swing.JTextField;
- import javax.swing.SwingUtilities;
- public class LoginMain {
- private JFrame frame;
- private JTextField userNameField;
- private JPasswordField passwordField;
- public LoginMain() {
- initalize();
- }
- private void initalize()
- {
- frame = new JFrame();
- frame.setBounds(100, 100, 450, 300);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.getContentPane().setLayout(null);
- frame.setTitle("Staff Portal");
- JLabel username = new JLabel("Username");
- username.setBounds(75, 90, 70, 15);
- frame.getContentPane().add(username);
- userNameField = new JTextField();
- userNameField.setBounds(200,85,130,25);
- frame.getContentPane().add(userNameField);
- userNameField.setColumns(10);
- JLabel password = new JLabel("Password");
- password.setBounds(75, 135, 60, 15);
- frame.getContentPane().add(password);
- passwordField = new JPasswordField();
- passwordField.setBounds(200,135,130,15);
- frame.getContentPane().add(passwordField);
- JButton btnLogin = new JButton("Login");
- btnLogin.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent evt) {
- String userName = userNameField.getText();
- String pw = passwordField.getText();
- if (userName.equals("username") && pw.equals("password")) {
- JOptionPane.showMessageDialog(frame, "You have succesfully logined.");
- }
- else {
- JOptionPane.showMessageDialog(frame, "Invalid username or password;");
- }
- }
- });
- btnLogin.setBounds(150, 190, 120, 30);
- frame.getContentPane().add(btnLogin);
- }
- public static void main(String[] args) {
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- try {
- LoginMain window = new LoginMain();
- window.frame.setVisible(true);
- }
- catch(Exception e){
- e.printStackTrace();
- }
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement